Files
Backend-Api/Company.Domain/EmployeeDocumentItemAgg/EmployeeDocumentItem.cs
2025-02-18 16:16:33 +03:30

107 lines
4.2 KiB
C#

using _0_Framework.Domain;
using Company.Domain.EmployeeDocumentsAdminSelectionAgg;
using Company.Domain.EmployeeDocumentsAgg;
using CompanyManagment.App.Contracts.EmployeeDocuments;
using System;
using System.Collections.Generic;
using _0_Framework.Application;
using Microsoft.AspNetCore.JsonPatch.Operations;
namespace Company.Domain.EmployeeDocumentItemAgg
{
public class EmployeeDocumentItem : EntityBase
{
public long WorkshopId { get; private set; }
public long EmployeeId { get; private set; }
public long UploaderId { get; private set; }
public UserType UploaderType { get; private set; }
public long ReviewedById { get; private set; }
public string RejectionReason { get; private set; }
public DocumentStatus DocumentStatus { get; private set; }
public long MediaId { get; private set; }
public DateTime? ConfirmationDateTime { get; private set; }
public DocumentItemLabel DocumentLabel { get; private set; }
public long EmployeeDocumentId { get; private set; }
public virtual EmployeeDocuments EmployeeDocuments { get; private set; }
public long? EmployeeDocumentsAdminViewId { get; private set; }
public EmployeeDocumentsAdminSelection EmployeeDocumentsAdminSelection { get; private set; }
public List<EmployeeDocumentItemLog> ItemLogs { get; private set; }
public EmployeeDocumentItem(long workshopId,long employeeId, long mediaId, long employeeDocumentId, DocumentItemLabel documentLabel, long uploaderId,
UserType uploaderType, DocumentStatus documentStatus = DocumentStatus.Unsubmitted)
{
MediaId = mediaId;
UploaderId = uploaderId;
UploaderType = uploaderType;
EmployeeId = employeeId;
WorkshopId = workshopId;
DocumentStatus = documentStatus;
if (documentStatus == DocumentStatus.Confirmed)
ConfirmationDateTime = DateTime.Now;
DocumentLabel = documentLabel;
EmployeeDocumentId = employeeDocumentId;
ItemLogs =
[
new EmployeeDocumentItemLog(EmployeeDocumentItemOperation.CreatedNewItem, uploaderId, uploaderType)
];
}
public void Confirm(long operatorId, UserType userType)
{
ReviewedById = operatorId;
DocumentStatus = DocumentStatus.Confirmed;
ConfirmationDateTime = DateTime.Now;
ItemLogs.Add(new EmployeeDocumentItemLog(EmployeeDocumentItemOperation.ConfirmedItem, operatorId, userType));
}
public void Reject(long operatorId, string rejectionReason, UserType userType)
{
RejectionReason = rejectionReason;
DocumentStatus = DocumentStatus.Rejected;
EmployeeDocuments.UpdateHasRejectedItems();
ReviewedById = operatorId;
ItemLogs.Add(new EmployeeDocumentItemLog(EmployeeDocumentItemOperation.RejectedItem, operatorId, userType, rejectionReason));
}
public void Delete(long operatorId, UserType operatorType)
{
DocumentStatus = DocumentStatus.Deleted;
ItemLogs.Add(new EmployeeDocumentItemLog(EmployeeDocumentItemOperation.DeletedItem, operatorId, operatorType));
}
public void AdminSelect(long adminViewId)
{
EmployeeDocumentsAdminViewId = adminViewId;
}
public void AdminDeselect()
{
EmployeeDocumentsAdminViewId = 0;
}
public void SubmitByClient(long operatorId,UserType operatorType)
{
DocumentStatus = DocumentStatus.SubmittedByClient;
ItemLogs.Add(new EmployeeDocumentItemLog(EmployeeDocumentItemOperation.SubmittedItems, operatorId, operatorType));
EmployeeDocuments.UpdateHasRejectedItems();
}
public void SubmitByAdmin(long operatorId, UserType operatorType)
{
DocumentStatus = DocumentStatus.SubmittedByAdmin;
ItemLogs.Add(new EmployeeDocumentItemLog(EmployeeDocumentItemOperation.SubmittedItems, operatorId, operatorType));
EmployeeDocuments.UpdateHasRejectedItems();
}
}
}