From a8274708314cb8393e173b269e5bd7661829e0fa Mon Sep 17 00:00:00 2001 From: mahan Date: Wed, 22 Oct 2025 15:19:17 +0330 Subject: [PATCH] feat: add API for editing old institution contracts with new properties --- ...etInstitutionContractListItemsViewModel.cs | 4 + .../InstitutionContractRepository.cs | 6 +- .../institutionContractController.cs | 190 ++++++++++++++++++ 3 files changed, 199 insertions(+), 1 deletion(-) diff --git a/CompanyManagment.App.Contracts/InstitutionContract/GetInstitutionContractListItemsViewModel.cs b/CompanyManagment.App.Contracts/InstitutionContract/GetInstitutionContractListItemsViewModel.cs index 65392104..123dc18a 100644 --- a/CompanyManagment.App.Contracts/InstitutionContract/GetInstitutionContractListItemsViewModel.cs +++ b/CompanyManagment.App.Contracts/InstitutionContract/GetInstitutionContractListItemsViewModel.cs @@ -87,6 +87,10 @@ public class GetInstitutionContractListItemsViewModel public long ContractingPartyId { get; set; } public List Workshops { get; set; } + + public bool IsInPersonContract { get; set; } + + public bool IsOldContract { get; set; } } public class InstitutionContractListWorkshop diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs index 0a2b0709..18c03a04 100644 --- a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs @@ -1310,7 +1310,11 @@ public class InstitutionContractRepository : RepositoryBasey.Services.ContractInPerson)??true, + IsOldContract = x.contract.WorkshopGroup?.CurrentWorkshops + .Any(y=>y.Price == 0)??true }; }).ToList() }; diff --git a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs index 00fdc34b..dad7ddf9 100644 --- a/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs +++ b/ServiceHost/Areas/Admin/Controllers/institutionContractController.cs @@ -534,6 +534,196 @@ public class institutionContractController : AdminBaseController var res = await _institutionContractApplication.ResendVerifyLink(institutionContractId); return res; } + + [HttpGet("edit-old/{id}")] + public ActionResult GetEditOldDetails(long id) + { + var representativList = new List(); + var contractingPartyList = new List(); + var res = _institutionContractApplication.GetDetails(id); + + var representative = new RepresentativeViewModel + { + Id = res.RepresentativeId, + FullName = res.RepresentativeName + }; + representativList.Add(representative); + var contractingParty = new PersonalContractingPartyViewModel + { + id = res.ContractingPartyId, + FullName = _contractingPartyApplication.GetFullName(res.ContractingPartyId) + }; + contractingPartyList.Add(contractingParty); + res.RepresentativeSelectList = + new SelectList(representativList, "Id", "FullName"); + res.ContractingPartiesSelectList = + new SelectList(contractingPartyList, "id", "FullName"); + + var employer = _employerApplication.GetEmployerByContracrtingPartyID(res.ContractingPartyId); + var emplId = employer.Select(x => x.Id).ToList(); + + var w = _workshopApplication.GetWorkshopsByEmployerId(emplId); + var workshopIds = w.Select(x => x.Id).ToList(); + var workshopCount = Convert.ToString(w.Count); + var pCount = 0; + if (workshopIds.Count > 0) + { + foreach (var workshopId in workshopIds) + { + var p = _workshopApplication.PersonnelCount(workshopId); + pCount += p; + } + + res.EmployeeCount = Convert.ToString(pCount); + } + else + { + res.EmployeeCount = "0"; + } + + res.WorkshopCount = workshopCount; + + + var contactInfo = _contactInfoApplication.GetContactInfolist(id); + if (contactInfo.Count > 0) + { + res.ContactInfoCounter = contactInfo.Count; + res.ContactInformationList = contactInfo; + } + else + { + res.ContactInfoCounter = 0; + } + + if (res.HasValueAddedTax == "true") + { + res.ContractAmount -= res.ValueAddedTax; + res.ContractAmountOAlone = res.ContractAmount.ToMoney(); + res.ValueAddedTaxStr = res.ValueAddedTax.ToMoney(); + } + else + { + res.ContractAmountOAlone = res.ContractAmountString; + res.ValueAddedTaxStr = "0"; + } + return res; + } + + [HttpPost("edit-old")] + public ActionResult EditOld([FromBody] EditInstitutionContract command) + { + var op = new OperationResult(); + var phoneNumber = command.ContactInformationList.FirstOrDefault(x => + x.SendSmsString == "true" && x.Position == "طرف قرارداد" && x.PhoneType == "شماره همراه"); + var conractingParty = _contractingPartyApplication.GetDetails(command.ContractingPartyId); + + if (conractingParty.IsLegal == "حقیقی" && string.IsNullOrWhiteSpace(conractingParty.Nationalcode)) + return new JsonResult(op.Failed("کد ملی طرف حساب وجود ندارد")); + if (conractingParty.IsLegal == "حقوقی" && string.IsNullOrWhiteSpace(conractingParty.NationalId)) + return new JsonResult(op.Failed("شناسه ملی طرف حساب وجود ندارد")); + if (phoneNumber == null) + return new JsonResult(op.Failed("تعیین شماره همراه با سمت طرف قرارداد اجباریست")); + //if (string.IsNullOrWhiteSpace(command.HasValueAddedTax)) + // command.HasValueAddedTax = "false"; + var result = _institutionContractApplication.Edit(command); + var contractingPartyId = _institutionContractApplication.GetDetails(result.SendId); + var counter = command.ContactInformationList.Count; + var getOldContarct = _institutionContractApplication.NewSearch(new InstitutionContractSearchModel() + { ContractingPartyId = contractingPartyId.ContractingPartyId, IsActiveString = "both" }).Where(x=>x.IsActiveString == "false" || x.IsActiveString == "blue").ToList(); + if (result.IsSuccedded && counter > 0) + { + + if (getOldContarct.Count > 0) + { + foreach (var item in getOldContarct) + { + _contactInfoApplication.RemoveContactInfo(item.Id); + foreach (var phone in command.ContactInformationList) + { + if (phone.PhoneNumber != null) + { + var contactinfo = new CreateContactInfo + { + InstitutionContractId = item.Id, + PhoneType = phone.PhoneType, + Position = phone.Position, + PhoneNumber = phone.PhoneNumber, + FnameLname = phone.FnameLname, + SendSms = phone.SendSmsString == "true" ? true : false + }; + _contactInfoApplication.Create(contactinfo); + } + + Thread.Sleep(500); + } + } + } + _contactInfoApplication.RemoveContactInfo(command.Id); + foreach (var item in command.ContactInformationList) + { + if (item.PhoneNumber != null) + { + var contactinfo = new CreateContactInfo + { + InstitutionContractId = result.SendId, + PhoneType = item.PhoneType, + Position = item.Position, + PhoneNumber = item.PhoneNumber, + FnameLname = item.FnameLname, + SendSms = item.SendSmsString == "true" ? true : false + }; + _contactInfoApplication.Create(contactinfo); + } + + Thread.Sleep(500); + } + + + //ساخت اکانت کلاینت + var userPass = conractingParty.IsLegal == "حقیقی" + ? conractingParty.Nationalcode + : conractingParty.NationalId; + var checkExistAccount = _accountApplication.CheckExistClientAccount(userPass); + if (!checkExistAccount) + { + + var createAcc = new RegisterAccount + { + Fullname = conractingParty.LName, + Username = userPass, + Password = userPass, + Mobile = phoneNumber.PhoneNumber, + NationalCode = userPass + }; + var res = _accountApplication.RegisterClient(createAcc); + if (res.IsSuccedded) + _institutionContractApplication.CreateContractingPartyAccount(command.ContractingPartyId, res.SendId); + } + } + //Thread.Sleep(500); + //for (int i = 0; i <= counter - 1; i++) + //{ + // if (command.ContactInformationList[i].PhoneNumber != null) + // { + + // var contactinfo = new CreateContactInfo() + // { + // InstitutionContractId = result.SendId, + // PhoneType = command.ContactInformationList[i].PhoneType, + // Position = command.ContactInformationList[i].Position, + // PhoneNumber = command.ContactInformationList[i].PhoneNumber, + // FnameLname = command.ContactInformationList[i].FnameLname, + // SendSms = command.ContactInformationList[i].SendSmsString == "true" ? true : false + // }; + // _contactInfoApplication.Create(contactinfo); + + // } + // Thread.Sleep(500); + //} + + + return result; + } }