117 lines
4.1 KiB
C#
117 lines
4.1 KiB
C#
using _0_Framework.Domain;
|
|
using Company.Domain.EmployeeAgg;
|
|
using Company.Domain.EmployeeDocumentItemAgg;
|
|
using Company.Domain.WorkshopAgg;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using CompanyManagment.App.Contracts.EmployeeDocuments;
|
|
using Microsoft.AspNetCore.Antiforgery;
|
|
|
|
namespace Company.Domain.EmployeeDocumentsAgg
|
|
{
|
|
public class EmployeeDocuments : EntityBase
|
|
{
|
|
|
|
public long EmployeeId { get; private set; }
|
|
public Employee Employee { get; private set; }
|
|
|
|
|
|
public long WorkshopId { get; private set; }
|
|
public Workshop Workshop { get; private set; }
|
|
|
|
|
|
public string Gender { get; private set; }
|
|
|
|
|
|
public bool IsConfirmed { get; private set; }
|
|
public bool RequiredItemsSubmittedByClient { get; private set; }
|
|
public bool IsSentToChecker { get; private set; }
|
|
public bool HasRejectedItems { get; set; }
|
|
|
|
|
|
//History of rejected and confirmed documents, lazy loading enabled
|
|
public virtual List<EmployeeDocumentItem> EmployeeDocumentItemCollection { get; } = [];
|
|
|
|
|
|
public EmployeeDocuments(long employeeId, long workshopId, string gender)
|
|
{
|
|
WorkshopId = workshopId;
|
|
EmployeeId = employeeId;
|
|
Gender = gender??string.Empty;
|
|
}
|
|
|
|
private EmployeeDocuments()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool UpdateIsSentToChecker()
|
|
{
|
|
|
|
var requiredItems = EmployeeDocumentRequiredItems.GetByGender(Gender);
|
|
|
|
var currentItems = EmployeeDocumentItemCollection.Where(x => x.DocumentStatus != DocumentStatus.Unsubmitted)
|
|
.GroupBy(x => x.DocumentLabel).Select(x => x.OrderByDescending(y => y.CreationDate).First());
|
|
var currentItemsFiltered = currentItems.Where(x => x.DocumentStatus is DocumentStatus.Confirmed or DocumentStatus.SubmittedByAdmin or DocumentStatus.SubmittedByClient)
|
|
.Select(x => new { x.DocumentStatus, x.DocumentLabel }).ToList();
|
|
|
|
|
|
// ReSharper disable once SimplifyLinqExpressionUseAll
|
|
if (!currentItemsFiltered.Any(x => x.DocumentStatus is DocumentStatus.SubmittedByAdmin or DocumentStatus.SubmittedByClient))
|
|
IsSentToChecker = false;
|
|
|
|
else
|
|
IsSentToChecker = requiredItems.All(x => currentItemsFiltered.Any(y=>y.DocumentLabel==x));
|
|
|
|
|
|
return IsSentToChecker;
|
|
|
|
}
|
|
|
|
|
|
public bool UpdateIsConfirmed()
|
|
{
|
|
var requiredItems = EmployeeDocumentRequiredItems.GetByGender(Gender);
|
|
|
|
var currentItems = EmployeeDocumentItemCollection.Where(x => x.DocumentStatus != DocumentStatus.Unsubmitted)
|
|
.GroupBy(x => x.DocumentLabel).Select(x => x.OrderByDescending(y => y.CreationDate).First());
|
|
var currentConfirmedItems=currentItems.Where(x => x.DocumentStatus == DocumentStatus.Confirmed).Select(x => x.DocumentLabel).ToList();
|
|
|
|
|
|
IsConfirmed = requiredItems.All(x => currentConfirmedItems.Contains(x));
|
|
|
|
|
|
return IsConfirmed;
|
|
}
|
|
|
|
public void UpdateRequiredItemsSubmittedByClient()
|
|
{
|
|
|
|
var requiredItems = EmployeeDocumentRequiredItems.GetByGender(Gender);
|
|
|
|
var currentItems = EmployeeDocumentItemCollection.Where(x => x.DocumentStatus != DocumentStatus.Unsubmitted)
|
|
.GroupBy(x => x.DocumentLabel).Select(x => x.OrderByDescending(y => y.CreationDate).First());
|
|
|
|
if (currentItems.Where(x => requiredItems.Contains(x.DocumentLabel))
|
|
.Any(x => x.DocumentStatus == DocumentStatus.SubmittedByClient))
|
|
RequiredItemsSubmittedByClient = true;
|
|
else
|
|
RequiredItemsSubmittedByClient = false;
|
|
|
|
}
|
|
|
|
public void UpdateHasRejectedItems()
|
|
{
|
|
var currentItems = EmployeeDocumentItemCollection.Where(x => x.DocumentStatus != DocumentStatus.Unsubmitted)
|
|
.GroupBy(x => x.DocumentLabel).Select(x => x.OrderByDescending(y => y.CreationDate).First());
|
|
if (currentItems.Any(y => y.DocumentStatus == DocumentStatus.Rejected))
|
|
HasRejectedItems = true;
|
|
else
|
|
HasRejectedItems= false;
|
|
}
|
|
|
|
}
|
|
}
|