-
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.
Merge remote-tracking branch 'origin/main'
# Conflicts: # .idea/.idea.Nezam.ESS/.idea/dataSources.xml # Nezam.Modular.ESS.WebApi/NezamEes.db
- Loading branch information
Showing
95 changed files
with
4,539 additions
and
150 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
188 changes: 188 additions & 0 deletions
188
...dules/Secretariat/Nezam.Modular.ESS.Secretariat.Domain/Documents/DocumentAggregateRoot.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,188 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Bonyan.Layer.Domain.Aggregates; | ||
using Bonyan.UserManagement.Domain.ValueObjects; | ||
using Nezam.Modular.ESS.Identity.Domain.User; | ||
using Nezam.Modular.ESS.Secretariat.Domain.Documents.Events; | ||
using System; | ||
|
||
namespace Nezam.Modular.ESS.Secretariat.Domain.Documents; | ||
|
||
public class DocumentAggregateRoot : FullAuditableAggregateRoot<DocumentId> | ||
{ | ||
public string Title { get; private set; } | ||
public string Content { get; private set; } | ||
public UserId SenderUserId { get; private set; } | ||
public UserEntity SenderUser { get; private set; } | ||
public DocumentType Type { get; private set; } | ||
public DocumentStatus Status { get; private set; } | ||
|
||
// Replace IReadOnlyCollection with List for EF Core compatibility | ||
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 DocumentAggregateRoot(string title, string content, UserId senderUserId, DocumentType type) | ||
{ | ||
Title = title; | ||
Content = content; | ||
SenderUserId = senderUserId; | ||
Type = type; | ||
Status = DocumentStatus.Draft; // Default status when a document is created | ||
} | ||
|
||
// Behavior to Update Document Content | ||
public void UpdateContent(string newContent) | ||
{ | ||
if (Status == DocumentStatus.Archive) | ||
throw new InvalidOperationException("Cannot update content of an archived document."); | ||
|
||
Content = newContent; | ||
AddDomainEvent(new DocumentContentUpdatedEvent(this.Id)); | ||
} | ||
|
||
// Behavior to Send Document | ||
public void Send() | ||
{ | ||
if (Status == DocumentStatus.Send) | ||
throw new InvalidOperationException("Document is already sent."); | ||
if (Status == DocumentStatus.Archive) | ||
throw new InvalidOperationException("Cannot send an archived document."); | ||
|
||
Status = DocumentStatus.Send; | ||
AddDomainEvent(new DocumentSentEvent(this.Id)); | ||
} | ||
|
||
// Behavior to Archive Document | ||
public void Archive() | ||
{ | ||
if (Status == DocumentStatus.Archive) | ||
throw new InvalidOperationException("Document is already archived."); | ||
|
||
Status = DocumentStatus.Archive; | ||
AddDomainEvent(new DocumentArchivedEvent(this.Id)); | ||
} | ||
|
||
// Behavior to Update Title | ||
public void UpdateTitle(string newTitle) | ||
{ | ||
if (Status == DocumentStatus.Archive) | ||
throw new InvalidOperationException("Cannot update title of an archived document."); | ||
|
||
Title = newTitle; | ||
AddDomainEvent(new DocumentTitleUpdatedEvent(this.Id)); | ||
} | ||
|
||
// Behavior to Change Document Type (e.g., Incoming, Outgoing, Internal) | ||
public void ChangeType(DocumentType newType) | ||
{ | ||
if (Status == DocumentStatus.Archive) | ||
throw new InvalidOperationException("Cannot change the type of an archived document."); | ||
|
||
Type = newType; | ||
AddDomainEvent(new DocumentTypeChangedEvent(this.Id)); | ||
} | ||
|
||
// Additional behavior: Revert Document to Draft (optional) | ||
public void RevertToDraft() | ||
{ | ||
if (Status == DocumentStatus.Archive) | ||
throw new InvalidOperationException("Cannot revert an archived document to draft."); | ||
|
||
Status = DocumentStatus.Draft; | ||
AddDomainEvent(new DocumentRevertedToDraftEvent(this.Id)); | ||
} | ||
|
||
// Attachment-related behaviors | ||
public void AddAttachment(string fileName, string fileType, long fileSize, string filePath) | ||
{ | ||
if (Status == DocumentStatus.Archive) | ||
throw new InvalidOperationException("Cannot add attachments to an archived document."); | ||
|
||
var attachment = new DocumentAttachmentEntity(fileName, fileType, fileSize, filePath); | ||
_attachments.Add(attachment); | ||
|
||
AddDomainEvent(new DocumentAttachmentAddedEvent(this.Id, attachment.Id)); | ||
} | ||
|
||
public void RemoveAttachment(DocumentAttachmentId attachmentId) | ||
{ | ||
var attachment = _attachments.FirstOrDefault(a => a.Id == attachmentId); | ||
if (attachment == null) | ||
throw new InvalidOperationException("Attachment not found."); | ||
|
||
_attachments.Remove(attachment); | ||
AddDomainEvent(new DocumentAttachmentRemovedEvent(this.Id, attachmentId)); | ||
} | ||
|
||
public void UpdateAttachment(DocumentAttachmentId attachmentId, string newFileName, string newFileType, long newFileSize, string newFilePath) | ||
{ | ||
var attachment = _attachments.FirstOrDefault(a => a.Id == attachmentId); | ||
if (attachment == null) | ||
throw new InvalidOperationException("Attachment not found."); | ||
|
||
attachment.UpdateFileInfo(newFileName, newFileType, newFileSize, newFilePath); | ||
AddDomainEvent(new DocumentAttachmentUpdatedEvent(this.Id, attachmentId)); | ||
} | ||
|
||
// Behavior to Add a Referral | ||
public DocumentReferralEntity AddReferral(UserId referrerUserId, UserId receiverUserId) | ||
{ | ||
var referral = new DocumentReferralEntity(this.Id, referrerUserId, receiverUserId); | ||
_referrals.Add(referral); | ||
|
||
AddDomainEvent(new DocumentReferralCreatedEvent(this.Id, referral.Id, receiverUserId, referrerUserId)); | ||
return referral; | ||
} | ||
|
||
// Behavior to Set Next Referral in Pipeline (Sequential Workflow) | ||
public void SetNextReferral(DocumentReferralId currentReferralId, DocumentReferralId nextReferralId) | ||
{ | ||
var currentReferral = _referrals.FirstOrDefault(r => r.Id == currentReferralId); | ||
if (currentReferral == null) | ||
throw new InvalidOperationException("Current referral not found."); | ||
|
||
currentReferral.SetNextReferral(nextReferralId); | ||
} | ||
|
||
// Behavior to Mark Referral as Viewed | ||
public void MarkReferralAsViewed(DocumentReferralId referralId) | ||
{ | ||
var referral = _referrals.FirstOrDefault(r => r.Id == referralId); | ||
if (referral == null) | ||
throw new InvalidOperationException("Referral not found."); | ||
|
||
referral.MarkAsViewed(); | ||
} | ||
|
||
public void RespondToReferral(DocumentReferralId referralId, string responseContent) | ||
{ | ||
// یافتن ارجاعی که باید به آن پاسخ داده شود | ||
var referral = _referrals.FirstOrDefault(r => r.Id == referralId); | ||
if (referral == null) | ||
throw new InvalidOperationException("Referral not found."); | ||
|
||
// اگر این ارجاع یا ارجاع موازی دیگری در این مرحله پاسخ داده نشده باشد، اجازه پاسخگویی میدهیم | ||
if (_referrals.Any(r => r.DocumentId == referral.DocumentId && r.Status == ReferralStatus.New && r.Id != referralId)) | ||
{ | ||
// ارجاعات موازی دیگر که جدید هستند، لغو میشوند | ||
foreach (var otherReferral in _referrals.Where(r => r.DocumentId == referral.DocumentId && r.Status == ReferralStatus.New && r.Id != referralId)) | ||
{ | ||
otherReferral.Cancel(); | ||
} | ||
} | ||
|
||
// ثبت پاسخ در ارجاع فعلی | ||
referral.Respond(responseContent); | ||
} | ||
|
||
|
||
|
||
// Behavior to Get Active Referrals (For parallel processing) | ||
public IEnumerable<DocumentReferralEntity> GetActiveReferrals() | ||
{ | ||
return _referrals.Where(r => !r.IsProcessed()); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...es/Secretariat/Nezam.Modular.ESS.Secretariat.Domain/Documents/DocumentAttachmentEntity.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,35 @@ | ||
using Bonyan.Layer.Domain.Entities; | ||
using System; | ||
|
||
namespace Nezam.Modular.ESS.Secretariat.Domain.Documents; | ||
|
||
public class DocumentAttachmentEntity : Entity<DocumentAttachmentId> | ||
{ | ||
public string FileName { get; private set; } | ||
public string FileType { get; private set; } | ||
public long FileSize { get; private set; } | ||
public string FilePath { get; private set; } | ||
public DateTime UploadDate { get; private set; } | ||
|
||
// Required for EF Core | ||
private DocumentAttachmentEntity() { } | ||
|
||
// Constructor | ||
public DocumentAttachmentEntity(string fileName, string fileType, long fileSize, string filePath) | ||
{ | ||
FileName = fileName; | ||
FileType = fileType; | ||
FileSize = fileSize; | ||
FilePath = filePath; | ||
UploadDate = DateTime.UtcNow; | ||
} | ||
|
||
// Method to update file details if needed | ||
public void UpdateFileInfo(string newFileName, string newFileType, long newFileSize, string newFilePath) | ||
{ | ||
FileName = newFileName; | ||
FileType = newFileType; | ||
FileSize = newFileSize; | ||
FilePath = newFilePath; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...ules/Secretariat/Nezam.Modular.ESS.Secretariat.Domain/Documents/DocumentReferralEntity.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,66 @@ | ||
using Bonyan.Layer.Domain.Entities; | ||
using Bonyan.UserManagement.Domain.ValueObjects; | ||
|
||
|
||
namespace Nezam.Modular.ESS.Secretariat.Domain.Documents; | ||
|
||
public class DocumentReferralEntity : Entity<DocumentReferralId> | ||
{ | ||
public DocumentId DocumentId { get; private set; } | ||
public UserId ReferrerUserId { get; private set; } // The user who created this referral | ||
public UserId ReceiverUserId { get; private set; } | ||
public ReferralStatus Status { get; private set; } | ||
public DateTime ReferralDate { get; private set; } | ||
public DateTime? ViewedDate { get; private set; } | ||
public DateTime? RespondedDate { get; private set; } | ||
public string ResponseContent { get; private set; } | ||
public DocumentReferralId? NextReferralId { get; private set; } // Link to the next referral in the pipeline | ||
|
||
// Updated Constructor with ReferrerUserId | ||
public DocumentReferralEntity(DocumentId documentId, UserId referrerUserId, UserId receiverUserId) | ||
{ | ||
DocumentId = documentId; | ||
ReferrerUserId = referrerUserId; | ||
ReceiverUserId = receiverUserId; | ||
Status = ReferralStatus.New; | ||
ReferralDate = DateTime.UtcNow; | ||
} | ||
|
||
// Behavior to mark referral as viewed by receiver | ||
public void MarkAsViewed() | ||
{ | ||
if (Status == ReferralStatus.Responded) | ||
throw new InvalidOperationException("Cannot mark a responded referral as viewed."); | ||
|
||
Status = ReferralStatus.Viewed; | ||
ViewedDate = DateTime.UtcNow; | ||
} | ||
|
||
// Behavior to respond to the referral | ||
public void Respond(string responseContent) | ||
{ | ||
if (Status == ReferralStatus.Responded) | ||
throw new InvalidOperationException("Referral has already been responded to."); | ||
|
||
Status = ReferralStatus.Responded; | ||
RespondedDate = DateTime.UtcNow; | ||
ResponseContent = responseContent; | ||
} | ||
|
||
public void Cancel() | ||
{ | ||
Status = ReferralStatus.Canceled; | ||
} | ||
|
||
// Behavior to set the next referral in the pipeline | ||
public void SetNextReferral(DocumentReferralId nextReferralId) | ||
{ | ||
NextReferralId = nextReferralId; | ||
} | ||
|
||
// Check if this referral has been fully processed (responded) | ||
public bool IsProcessed() | ||
{ | ||
return Status == ReferralStatus.Responded; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...Secretariat/Nezam.Modular.ESS.Secretariat.Domain/Documents/Enumerations/DocumentStatus.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,13 @@ | ||
using Bonyan.Layer.Domain.Enumerations; | ||
|
||
namespace Nezam.Modular.ESS.Secretariat.Domain.Documents; | ||
|
||
public class DocumentStatus : Enumeration | ||
{ | ||
public static readonly DocumentStatus Draft = new DocumentStatus(0, nameof(Draft)); | ||
public static readonly DocumentStatus Send = new DocumentStatus(1, nameof(Send)); | ||
public static readonly DocumentStatus Archive = new DocumentStatus(1, nameof(Archive)); | ||
public DocumentStatus(int id, string name) : base(id, name) | ||
{ | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...s/Secretariat/Nezam.Modular.ESS.Secretariat.Domain/Documents/Enumerations/DocumentType.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,13 @@ | ||
using Bonyan.Layer.Domain.Enumerations; | ||
|
||
namespace Nezam.Modular.ESS.Secretariat.Domain.Documents; | ||
|
||
public class DocumentType : Enumeration | ||
{ | ||
public static readonly DocumentType Outgoing = new DocumentType(0, nameof(Outgoing)); | ||
public static readonly DocumentType Incoming = new DocumentType(1, nameof(Incoming)); | ||
public static readonly DocumentType Internal = new DocumentType(2, nameof(Internal)); | ||
public DocumentType(int id, string name) : base(id, name) | ||
{ | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...Secretariat/Nezam.Modular.ESS.Secretariat.Domain/Documents/Enumerations/ReferralStatus.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,11 @@ | ||
using Bonyan.Layer.Domain.Enumerations; | ||
|
||
public class ReferralStatus : Enumeration | ||
{ | ||
public static readonly ReferralStatus New = new ReferralStatus(0, nameof(New)); | ||
public static readonly ReferralStatus Viewed = new ReferralStatus(1, nameof(Viewed)); | ||
public static readonly ReferralStatus Responded = new ReferralStatus(2, nameof(Responded)); | ||
public static readonly ReferralStatus Canceled = new ReferralStatus(3, nameof(Canceled)); // وضعیت جدید | ||
|
||
public ReferralStatus(int id, string name) : base(id, name) { } | ||
} |
13 changes: 13 additions & 0 deletions
13
...ecretariat/Nezam.Modular.ESS.Secretariat.Domain/Documents/Events/DocumentArchivedEvent.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,13 @@ | ||
using Bonyan.Layer.Domain.Events; | ||
|
||
namespace Nezam.Modular.ESS.Secretariat.Domain.Documents.Events; | ||
|
||
public class DocumentArchivedEvent : DomainEventBase | ||
{ | ||
public DocumentId DocumentId { get; } | ||
|
||
public DocumentArchivedEvent(DocumentId documentId) | ||
{ | ||
DocumentId = documentId; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...iat/Nezam.Modular.ESS.Secretariat.Domain/Documents/Events/DocumentAttachmentAddedEvent.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,15 @@ | ||
using Bonyan.Layer.Domain.Events; | ||
|
||
namespace Nezam.Modular.ESS.Secretariat.Domain.Documents.Events; | ||
|
||
public class DocumentAttachmentAddedEvent : DomainEventBase | ||
{ | ||
public DocumentId DocumentId { get; } | ||
public DocumentAttachmentId AttachmentId { get; } | ||
|
||
public DocumentAttachmentAddedEvent(DocumentId documentId, DocumentAttachmentId attachmentId) | ||
{ | ||
DocumentId = documentId; | ||
AttachmentId = attachmentId; | ||
} | ||
} |
Oops, something went wrong.