-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
1,287 additions
and
3,039 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
New/modules/Secretariat/Nezam.Modular.ESS.Secretariat.Application/Documents/DocumentDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Bonyan.Layer.Application.Dto; | ||
using Bonyan.UserManagement.Domain.ValueObjects; | ||
using Nezam.Modular.ESS.Identity.Application.Users.Dto; | ||
using Nezam.Modular.ESS.Secretariat.Domain.Documents; | ||
using Nezam.Modular.ESS.Secretariat.Domain.Documents.Enumerations; | ||
using Nezam.Modular.ESS.Secretariat.Domain.Documents.ValueObjects; | ||
|
||
namespace Nezam.Modular.ESS.Secretariat.Application.Documents; | ||
|
||
public class DocumentDto : FullAuditableAggregateRootDto<DocumentId> | ||
{ | ||
public string Title { get; set; } | ||
public string Content { get; set; } | ||
|
||
public UserId OwnerUserId { get; private set; } | ||
public UserDto OwnerUser { get; private set; } | ||
|
||
public DocumentType Type { get; private set; } | ||
public DocumentStatus Status { get; private set; } | ||
|
||
private readonly List<DocumentAttachmentEntity> _attachments = new List<DocumentAttachmentEntity>(); | ||
public IReadOnlyList<DocumentAttachmentEntity> Attachments => _attachments; | ||
|
||
private readonly List<DocumentReferralEntity> _referrals = new List<DocumentReferralEntity>(); | ||
public IReadOnlyList<DocumentReferralEntity> Referrals => _referrals; | ||
|
||
public List<DocumentActivityLogDto> ActivityLogs { get; set; } | ||
|
||
} | ||
|
||
public class DocumentActivityLogDto : EntityDto<DocumentActivityLogId> | ||
{ | ||
public DateTime ActivityDate { get; private set; } | ||
public UserId UserId { get; private set; } | ||
public string Key { get; private set; } | ||
public string Description { get; private set; } | ||
|
||
} | ||
public class DocumentUpdateDto | ||
{ | ||
public string Title { get; set; } | ||
public string Content { get; set; } | ||
public int Type { get; set; } | ||
} | ||
|
45 changes: 45 additions & 0 deletions
45
...odules/Secretariat/Nezam.Modular.ESS.Secretariat.Application/Documents/DocumentProfile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Reflection; | ||
using AutoMapper; | ||
using Bonyan.Layer.Domain.Enumerations; | ||
using Microsoft.Extensions.Localization; | ||
using Nezam.Modular.ESS.Secretariat.Application.Documents; | ||
using Nezam.Modular.ESS.Secretariat.Application.Resources; | ||
using Nezam.Modular.ESS.Secretariat.Domain.Documents; | ||
using Nezam.Modular.ESS.Secretariat.Domain.Documents.Enumerations; | ||
|
||
namespace Nezam.Modular.ESS.Identity.Application.Employers | ||
{ | ||
public class DocumentProfile : Profile | ||
{ | ||
public DocumentProfile() | ||
{ | ||
// Map DocumentStatus with localization using the EnumerationTranslationResolver | ||
CreateMap<DocumentAggregateRoot, DocumentDto>(); | ||
|
||
// Map Description with DocumentDescriptionConverter | ||
CreateMap<DocumentActivityLogEntity, DocumentActivityLogDto>() | ||
.ForMember(d => d.Description, | ||
opt => opt.ConvertUsing<DocumentDescriptionConverter, string>(src => src.Key)); | ||
} | ||
} | ||
|
||
// Custom converter to apply localization on string properties | ||
public class DocumentDescriptionConverter : IValueConverter<string, string> | ||
{ | ||
private readonly IStringLocalizer<DocumentTranslates> _localizer; | ||
|
||
// Inject IStringLocalizer through constructor | ||
public DocumentDescriptionConverter(IStringLocalizer<DocumentTranslates> localizer) | ||
{ | ||
_localizer = localizer; | ||
} | ||
|
||
public string Convert(string source, ResolutionContext context) | ||
{ | ||
// Use the localizer to translate the source string, defaulting to source if no translation is found | ||
return string.IsNullOrEmpty(source) ? source : _localizer[source]; | ||
} | ||
} | ||
|
||
// Custom resolver to translate Enumeration-based properties using IStringLocalizer | ||
} |
130 changes: 130 additions & 0 deletions
130
...odules/Secretariat/Nezam.Modular.ESS.Secretariat.Application/Documents/DocumentService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
using Bonyan.Layer.Application.Services; | ||
using Bonyan.Layer.Domain.Enumerations; | ||
using Bonyan.UserManagement.Domain.ValueObjects; | ||
using Nezam.Modular.ESS.Identity.Domain.User; | ||
using Nezam.Modular.ESS.Secretariat.Domain.Documents; | ||
using Nezam.Modular.ESS.Secretariat.Domain.Documents.Enumerations; | ||
using Nezam.Modular.ESS.Secretariat.Domain.Documents.Repositories; | ||
using Nezam.Modular.ESS.Secretariat.Domain.Documents.ValueObjects; | ||
|
||
namespace Nezam.Modular.ESS.Secretariat.Application.Documents; | ||
|
||
public class DocumentApplicationService : ApplicationService, IDocumentApplicationService | ||
{ | ||
private IDocumentRepository DocumentRepository => LazyServiceProvider.LazyGetRequiredService<IDocumentRepository>(); | ||
|
||
private IDocumentReadOnlyRepository DocumentReadOnlyRepository => | ||
LazyServiceProvider.LazyGetRequiredService<IDocumentReadOnlyRepository>(); | ||
|
||
private IUserRepository UserRepository => LazyServiceProvider.LazyGetRequiredService<IUserRepository>(); | ||
|
||
// 1. ایجاد یا برگرداندن نامه پیشنویس خالی | ||
public async Task<DocumentDto> CreateOrGetEmptyDraftAsync(UserId userId) | ||
{ | ||
// تلاش برای یافتن یک نامه پیشنویس خالی بدون گیرنده و پیوست | ||
var existingDraft = await DocumentReadOnlyRepository.GetEmptyDraftByUserAsync(userId); | ||
if (existingDraft != null && existingDraft.Status == DocumentStatus.Draft && !existingDraft.Attachments.Any() && | ||
!existingDraft.Referrals.Any()) | ||
{ | ||
return Mapper.Map<DocumentDto>(existingDraft); | ||
} | ||
|
||
// ایجاد نامه پیشنویس جدید در صورت عدم وجود نامه پیشنویس | ||
var newDraft = new DocumentAggregateRoot( | ||
title: string.Empty, | ||
content: string.Empty, | ||
senderUserId: userId, | ||
type: DocumentType.Internal | ||
); | ||
|
||
await DocumentRepository.AddAsync(newDraft); | ||
return Mapper.Map<DocumentDto>(newDraft); | ||
} | ||
|
||
public async Task<DocumentDto> UpdateAsync(DocumentId documentId, DocumentUpdateDto dto, UserId userId) | ||
{ | ||
var document = await DocumentReadOnlyRepository.GetByIdAsync(documentId); | ||
if (document == null) | ||
throw new Exception("documentId"); | ||
|
||
document.UpdateContent(dto.Content, userId); | ||
document.UpdateTitle(dto.Title, userId); | ||
var type = Enumeration.FromId<DocumentType>(dto.Type); | ||
|
||
if (type != null) | ||
{ | ||
document.ChangeType(type, userId); | ||
} | ||
|
||
await DocumentRepository.UpdateAsync(document); | ||
|
||
return Mapper.Map<DocumentDto>(document); | ||
} | ||
|
||
// 2. اضافه کردن گیرنده اصلی | ||
public async Task AddPrimaryRecipientAsync(DocumentId documentId, UserId receiverUserId, UserId currentUserId) | ||
{ | ||
var document = await DocumentReadOnlyRepository.GetByIdAsync(documentId); | ||
if (document == null) | ||
throw new Exception("documentId"); | ||
|
||
// بررسی ارجاعات موجود برای این گیرنده خاص | ||
var existingReferral = document.Referrals | ||
.FirstOrDefault(r => r.ReceiverUserId == receiverUserId && | ||
r.Status == ReferralStatus.Pending); | ||
// اضافه کردن گیرنده به عنوان ارجاع اصلی | ||
document.AddInitialReferral(receiverUserId, currentUserId); | ||
await DocumentRepository.UpdateAsync(document); | ||
} | ||
|
||
// 3. اضافه کردن پیوست | ||
public async Task AddAttachmentAsync(DocumentId documentId, string fileName, string fileType, long fileSize, | ||
string filePath, UserId userId) | ||
{ | ||
var document = await DocumentReadOnlyRepository.GetByIdAsync(documentId); | ||
if (document == null) | ||
throw new Exception("documentId"); | ||
|
||
document.AddAttachment(fileName, fileType, fileSize, filePath, userId); | ||
await DocumentRepository.UpdateAsync(document); | ||
} | ||
|
||
// 4. حذف پیوست | ||
public async Task RemoveAttachmentAsync(DocumentId documentId, DocumentAttachmentId attachmentId, UserId userId) | ||
{ | ||
var document = await DocumentReadOnlyRepository.GetByIdAsync(documentId); | ||
if (document == null) | ||
throw new Exception("documentId"); | ||
|
||
document.RemoveAttachment(attachmentId, userId); | ||
await DocumentRepository.UpdateAsync(document); | ||
} | ||
|
||
// 5. مشاهده جزئیات نامه | ||
public async Task<DocumentDto> ViewDocumentDetailsAsync(DocumentId documentId) | ||
{ | ||
var document = await DocumentReadOnlyRepository.GetByIdAsync(documentId); | ||
if (document == null) | ||
throw new Exception("documentId"); | ||
|
||
return Mapper.Map<DocumentDto>(document); | ||
} | ||
|
||
// 6. ارسال نامه | ||
public async Task SendDocumentAsync(DocumentId documentId, UserId senderId) | ||
{ | ||
var document = await DocumentReadOnlyRepository.GetByIdAsync(documentId); | ||
if (document == null) | ||
throw new Exception("documentId"); | ||
|
||
// بررسی وجود گیرنده و وضعیت پیشنویس بودن نامه | ||
if (!document.Referrals.Any()) | ||
throw new InvalidOperationException("Cannot send a document without recipients."); | ||
if (document.Status != DocumentStatus.Draft) | ||
throw new InvalidOperationException("Only draft documents can be sent."); | ||
|
||
// تغییر وضعیت نامه به "Published" | ||
document.Publish(senderId); | ||
await DocumentRepository.UpdateAsync(document); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...dules/Secretariat/Nezam.Modular.ESS.Secretariat.Application/Documents/IDocumentSerivce.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Bonyan.Layer.Application.Services; | ||
using Bonyan.UserManagement.Domain.ValueObjects; | ||
using Nezam.Modular.ESS.Secretariat.Domain.Documents.ValueObjects; | ||
|
||
namespace Nezam.Modular.ESS.Secretariat.Application.Documents; | ||
|
||
public interface IDocumentApplicationService : IApplicationService | ||
{ | ||
Task<DocumentDto> CreateOrGetEmptyDraftAsync(UserId userId); | ||
Task<DocumentDto> UpdateAsync(DocumentId documentId, DocumentUpdateDto dto, UserId userId); | ||
Task AddPrimaryRecipientAsync(DocumentId documentId, UserId receiverUserId, UserId currentUserId); | ||
Task AddAttachmentAsync(DocumentId documentId, string fileName, string fileType, long fileSize, string filePath, UserId userId); | ||
Task RemoveAttachmentAsync(DocumentId documentId, DocumentAttachmentId attachmentId, UserId userId); | ||
Task<DocumentDto> ViewDocumentDetailsAsync(DocumentId documentId); | ||
Task SendDocumentAsync(DocumentId documentId, UserId senderId); | ||
} |
42 changes: 42 additions & 0 deletions
42
...ezam.Modular.ESS.Secretariat.Application/Nezam.Modular.ESS.Secretariat.Application.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Bonyan.Layer.Application" Version="1.1.5" /> | ||
<PackageReference Include="Bonyan.Layer.Domain" Version="1.1.5" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\Nezam.Modular.ESS.Identity.Application\Nezam.Modular.ESS.Identity.Application.csproj" /> | ||
<ProjectReference Include="..\Nezam.Modular.ESS.Secretariat.Domain\Nezam.Modular.ESS.Secretariat.Domain.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<EmbeddedResource Update="Resources\DocumentTranslates.en.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>DocumentProfile.en.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
<EmbeddedResource Update="Resources\DocumentTranslates.fa.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>DocumentProfile.fa.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Update="Resources\DocumentTranslates.en.Designer.cs"> | ||
<DesignTime>True</DesignTime> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>DocumentTranslates.en.resx</DependentUpon> | ||
</Compile> | ||
<Compile Update="Resources\DocumentTranslates.fa.Designer.cs"> | ||
<DesignTime>True</DesignTime> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>DocumentTranslates.fa.resx</DependentUpon> | ||
</Compile> | ||
</ItemGroup> | ||
</Project> |
29 changes: 29 additions & 0 deletions
29
.../Secretariat/Nezam.Modular.ESS.Secretariat.Application/NezamEssSecretariatDomainModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Bonyan.AutoMapper; | ||
using Bonyan.Modularity; | ||
using Bonyan.Modularity.Abstractions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Nezam.Modular.ESS.Identity.Application.Employers; | ||
using Nezam.Modular.ESS.Secretariat.Application.Documents; | ||
using Nezam.Modular.ESS.Secretariat.Domain; | ||
|
||
namespace Nezam.Modular.ESS.Secretariat.Application; | ||
|
||
public class NezamEssSecretariatApplicationModule : Module | ||
{ | ||
public NezamEssSecretariatApplicationModule() | ||
{ | ||
DependOn<NezamEssSecretariatDomainModule>(); | ||
} | ||
public override Task OnConfigureAsync(ServiceConfigurationContext context) | ||
{ | ||
context.Services.AddTransient<IDocumentApplicationService, DocumentApplicationService>(); | ||
|
||
context.Services.Configure<BonyanAutoMapperOptions>(c => | ||
{ | ||
c.AddMaps<NezamEssSecretariatApplicationModule>(); | ||
}); | ||
|
||
context.Services.AddLocalization(); | ||
return base.OnConfigureAsync(context); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...les/Secretariat/Nezam.Modular.ESS.Secretariat.Application/Resources/DocumentTranslates.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Nezam.Modular.ESS.Secretariat.Application.Resources; | ||
|
||
public abstract class DocumentTranslates | ||
{ | ||
|
||
} |
Oops, something went wrong.