feat: update InstitutionContractAmendmentChange to include roll call options and current workshop ID
This commit is contained in:
@@ -291,14 +291,12 @@ public class InstitutionContractAmendment : EntityBase
|
||||
public class InstitutionContractAmendmentChange : EntityBase
|
||||
{
|
||||
private InstitutionContractAmendmentChange() { }
|
||||
private InstitutionContractAmendmentChange(long institutionContractAmendmentId,
|
||||
InstitutionContractAmendment institutionContractAmendment, InstitutionContractAmendmentChangeType changeType,
|
||||
DateTime changeDateGr, bool? hasRollCallPlan, bool? hasCustomizeCheckoutPlan, bool? hasContractPlan,
|
||||
public InstitutionContractAmendmentChange(InstitutionContractAmendmentChangeType changeType,
|
||||
DateTime changeDateGr, bool? hasCustomizeCheckoutPlan, bool? hasContractPlan,
|
||||
bool? hasContractPlanInPerson, bool? hasInsurancePlan, bool? hasInsurancePlanInPerson, int? personnelCount,
|
||||
long? workshopDetailsId)
|
||||
bool? hasRollCallPlan, bool? hasRollCallInPerson,
|
||||
long? currentWorkshopId)
|
||||
{
|
||||
InstitutionContractAmendmentId = institutionContractAmendmentId;
|
||||
InstitutionContractAmendment = institutionContractAmendment;
|
||||
ChangeType = changeType;
|
||||
ChangeDateGr = changeDateGr;
|
||||
HasRollCallPlan = hasRollCallPlan;
|
||||
@@ -308,7 +306,8 @@ public class InstitutionContractAmendmentChange : EntityBase
|
||||
HasInsurancePlan = hasInsurancePlan;
|
||||
HasInsurancePlanInPerson = hasInsurancePlanInPerson;
|
||||
PersonnelCount = personnelCount;
|
||||
WorkshopDetailsId = workshopDetailsId;
|
||||
CurrentWorkshopId = currentWorkshopId;
|
||||
HasRollCallInPerson = hasRollCallInPerson;
|
||||
}
|
||||
|
||||
public long InstitutionContractAmendmentId { get; private set; }
|
||||
@@ -321,6 +320,8 @@ public class InstitutionContractAmendmentChange : EntityBase
|
||||
/// </summary>
|
||||
public bool? HasRollCallPlan { get; private set; }
|
||||
|
||||
public bool? HasRollCallInPerson { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// پلن فیش غیر رسمی
|
||||
/// </summary>
|
||||
@@ -354,7 +355,7 @@ public class InstitutionContractAmendmentChange : EntityBase
|
||||
/// <summary>
|
||||
/// تعداد کارگاه
|
||||
/// </summary>
|
||||
public long? WorkshopDetailsId { get; private set; }
|
||||
public long? CurrentWorkshopId { get; private set; }
|
||||
}
|
||||
|
||||
public enum InstitutionContractAmendmentChangeType
|
||||
|
||||
@@ -2690,11 +2690,71 @@ public class InstitutionContractRepository : RepositoryBase<long, InstitutionCon
|
||||
{
|
||||
amount = amendmentTemp.OneTimePayment.PaymentAmount.MoneyToDouble();
|
||||
}
|
||||
var newWorkshops = amendmentTemp.NewWorkshops.Where(x=>x.CurrentWorkshopId ==0).ToList();
|
||||
|
||||
var newWorkshops = amendmentTemp
|
||||
.NewWorkshops.Where(x=>x.CurrentWorkshopId ==0).ToList();
|
||||
|
||||
var newWorkshopTempIds = newWorkshops.Select(x=>x.Id);
|
||||
|
||||
var changes = newWorkshops.Select(x=>
|
||||
new InstitutionContractAmendmentChange(InstitutionContractAmendmentChangeType.WorkshopCreated,
|
||||
DateTime.Now,x.CustomizeCheckout,x.ContractAndCheckout,x.ContractAndCheckoutInPerson,
|
||||
x.Insurance,x.InsuranceInPerson,x.CountPerson,x.RollCall,x.RollCallInPerson,0));
|
||||
|
||||
var changedWorkshops = amendmentTemp.NewWorkshops
|
||||
.Where(x => !newWorkshopTempIds.Contains(x.Id));
|
||||
|
||||
foreach (var changedWorkshop in changedWorkshops)
|
||||
{
|
||||
var prev = amendmentTemp.PrevWorkshops.FirstOrDefault(x => x.Id == changedWorkshop.Id);
|
||||
if (prev == null)
|
||||
throw new BadRequestException("دیتای وارد شده ناقص ذخیره شده است");
|
||||
|
||||
// مقایسه مقادیر بولین بین prev و changedWorkshop برای تشخیص تغییرات
|
||||
var changedBooleans = new Dictionary<string, (bool Previous, bool Current)>();
|
||||
|
||||
if (prev.CustomizeCheckout != changedWorkshop.CustomizeCheckout)
|
||||
changedBooleans.Add("CustomizeCheckout", (prev.CustomizeCheckout, changedWorkshop.CustomizeCheckout));
|
||||
|
||||
if (prev.ContractAndCheckout != changedWorkshop.ContractAndCheckout)
|
||||
changedBooleans.Add("ContractAndCheckout", (prev.ContractAndCheckout, changedWorkshop.ContractAndCheckout));
|
||||
|
||||
if (prev.ContractAndCheckoutInPerson != changedWorkshop.ContractAndCheckoutInPerson)
|
||||
changedBooleans.Add("ContractAndCheckoutInPerson", (prev.ContractAndCheckoutInPerson, changedWorkshop.ContractAndCheckoutInPerson));
|
||||
|
||||
if (prev.Insurance != changedWorkshop.Insurance)
|
||||
changedBooleans.Add("Insurance", (prev.Insurance, changedWorkshop.Insurance));
|
||||
|
||||
if (prev.InsuranceInPerson != changedWorkshop.InsuranceInPerson)
|
||||
changedBooleans.Add("InsuranceInPerson", (prev.InsuranceInPerson, changedWorkshop.InsuranceInPerson));
|
||||
|
||||
if (prev.RollCall != changedWorkshop.RollCall)
|
||||
changedBooleans.Add("RollCall", (prev.RollCall, changedWorkshop.RollCall));
|
||||
|
||||
if (prev.RollCallInPerson != changedWorkshop.RollCallInPerson)
|
||||
changedBooleans.Add("RollCallInPerson", (prev.RollCallInPerson, changedWorkshop.RollCallInPerson));
|
||||
|
||||
// اگر تغییری وجود داشته باشد، آن را به لیست تغییرات اضافه کن
|
||||
if (changedBooleans.Any())
|
||||
{
|
||||
var change = new InstitutionContractAmendmentChange(
|
||||
InstitutionContractAmendmentChangeType.WorkshopUpdated,
|
||||
DateTime.Now,
|
||||
changedWorkshop.CustomizeCheckout,
|
||||
changedWorkshop.ContractAndCheckout,
|
||||
changedWorkshop.ContractAndCheckoutInPerson,
|
||||
changedWorkshop.Insurance,
|
||||
changedWorkshop.InsuranceInPerson,
|
||||
changedWorkshop.CountPerson,
|
||||
changedWorkshop.RollCall,
|
||||
changedWorkshop.RollCallInPerson,
|
||||
changedWorkshop.Id);
|
||||
|
||||
changes = changes.Append(change);
|
||||
}
|
||||
}
|
||||
|
||||
var amendment = new InstitutionContractAmendment(institutionContract.id,installments,amount,
|
||||
request.IsInstallment,,request.LawId);
|
||||
request.IsInstallment,new List<InstitutionContractAmendmentChange>(),request.LawId);
|
||||
institutionContract.AddAmendment(amendment);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user