diff --git a/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs b/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs index e10f15ed..54f0e897 100644 --- a/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs +++ b/Company.Domain/InstitutionContractAgg/IInstitutionContractRepository.cs @@ -159,4 +159,5 @@ public interface IInstitutionContractRepository : IRepository GetIdByInstallmentId(long installmentId); + Task GetPreviousContract(long currentInstitutionContractId); } \ No newline at end of file diff --git a/CompanyManagment.Application/InstitutionContractApplication.cs b/CompanyManagment.Application/InstitutionContractApplication.cs index bebd9ab9..6434a78b 100644 --- a/CompanyManagment.Application/InstitutionContractApplication.cs +++ b/CompanyManagment.Application/InstitutionContractApplication.cs @@ -1608,7 +1608,10 @@ public class InstitutionContractApplication : IInstitutionContractApplication } institutionContract.SetSigningType(signingType); - + var previousInstitutionContract = await _institutionContractRepository + .GetPreviousContract(institutionContract.id); + previousInstitutionContract.DeActive(); + ReActiveAllAfterCreateNew(institutionContract.ContractingPartyId); await _institutionContractRepository.SaveChangesAsync(); return op.Succcedded(); } diff --git a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs index bfb11406..c6121f80 100644 --- a/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs +++ b/CompanyManagment.EFCore/Repository/InstitutionContractRepository.cs @@ -2834,8 +2834,6 @@ public class InstitutionContractRepository : RepositoryBasex.id ==contractingPartyId); - - if (contractingParty != null) - { - if (contractingParty.IsActiveString == "false") - { - contractingParty.Active(); - _context.SaveChanges(); - } - - var employers = - _employerRepository.GetEmployerByContracrtingPartyID(contractingPartyId); - - foreach (var employer in employers) - { - var res = _employerRepository.ActiveAll(employer.Id); - } - } - } #endregion @@ -4830,7 +4806,20 @@ public class InstitutionContractRepository : RepositoryBase x.Installments.Any(i => i.Id == installmentId)) .Select(x => x.id).FirstOrDefaultAsync(); } - + + public async Task GetPreviousContract(long currentInstitutionContractId) + { + var institutionContract =await _context.InstitutionContractSet + .FirstOrDefaultAsync(x=>x.id ==currentInstitutionContractId); + if (institutionContract == null) + return null; + var previousContract = await _context.InstitutionContractSet + .Where(x => x.ContractingPartyId == institutionContract.ContractingPartyId) + .Where(x => x.ContractStartGr < institutionContract.ContractStartGr) + .OrderByDescending(x => x.ContractEndGr) + .FirstOrDefaultAsync(); + return previousContract; + } #endregion diff --git a/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs b/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs index 7d6eedfd..660a659c 100644 --- a/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs +++ b/ServiceHost/Areas/AdminNew/Pages/Company/AndroidApk/Index.cshtml.cs @@ -52,6 +52,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk private readonly IOnlinePayment _onlinePayment; private readonly IFaceEmbeddingService _faceEmbeddingService; private readonly IAuthHelper _authHelper; + private readonly IInstitutionContractApplication _institutionContractApplication; [BindProperty] public IFormFile File { get; set; } @@ -77,7 +78,8 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk public IndexModel(IAndroidApkVersionApplication application, IRollCallDomainService rollCallDomainService, CompanyContext context, AccountContext accountContext, IHttpClientFactory httpClientFactory, IOptions appSetting, - ITemporaryClientRegistrationApplication clientRegistrationApplication, IOnlinePayment onlinePayment, IFaceEmbeddingService faceEmbeddingService, IAuthHelper authHelper) + ITemporaryClientRegistrationApplication clientRegistrationApplication, IOnlinePayment onlinePayment, + IFaceEmbeddingService faceEmbeddingService, IAuthHelper authHelper, IInstitutionContractApplication institutionContractApplication) { _application = application; _rollCallDomainService = rollCallDomainService; @@ -88,6 +90,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk _onlinePayment = onlinePayment; _faceEmbeddingService = faceEmbeddingService; _authHelper = authHelper; + _institutionContractApplication = institutionContractApplication; _paymentGateway = new SepehrPaymentGateway(httpClientFactory); } @@ -152,31 +155,60 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk { //await UpdateInstitutionContract(); //await UpdateFaceEmbeddingNames(); - await SetInstitutionContractSigningType(); + //await SetInstitutionContractSigningType(); + await ReActivateInstitution(); ViewData["message"] = "تومام یک"; return Page(); } + private async System.Threading.Tasks.Task ReActivateInstitution() + { + var blueInstitutionContracts = await _context.InstitutionContractSet.Where(x => + x.IsActiveString == "blue").ToListAsync(); + + + var blueContracts = new List(); + + foreach (var blueContract in blueInstitutionContracts) + { + var verifiedContracts = await _context.InstitutionContractSet + .Where(x => x.ContractingPartyId == blueContract.ContractingPartyId + && x.VerificationStatus == InstitutionContractVerificationStatus.Verified + && x.ContractStartGr > blueContract.ContractEndGr) + .ToListAsync(); + + if (verifiedContracts.Any()) + { + blueContracts.Add(blueContract); + } + } + + foreach (var institutionContract in blueContracts) + { + institutionContract.DeActive(); + _institutionContractApplication.ReActiveAllAfterCreateNew(institutionContract.ContractingPartyId); + } + } + private async System.Threading.Tasks.Task SetInstitutionContractSigningType() { var query = _context.InstitutionContractSet - .Where(x=>x.VerificationStatus != InstitutionContractVerificationStatus.PendingForVerify); - - - var otpSigned = query.Where(x=>x.VerifierFullName != null && x.LawId != 0).ToList(); + .Where(x => x.VerificationStatus != InstitutionContractVerificationStatus.PendingForVerify); + + + var otpSigned = query.Where(x => x.VerifierFullName != null && x.LawId != 0).ToList(); foreach (var institutionContract in otpSigned) { institutionContract.SetSigningType(InstitutionContractSigningType.OtpBased); } - var lagacySigned = query.Where(x=>x.VerifierFullName == null && x.LawId == 0).ToList(); + + var lagacySigned = query.Where(x => x.VerifierFullName == null && x.LawId == 0).ToList(); foreach (var institutionContract in lagacySigned) { institutionContract.SetSigningType(InstitutionContractSigningType.Legacy); } await _context.SaveChangesAsync(); - - } public async Task OnPostShiftDateNew2() @@ -326,6 +358,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk //TranslateCode(result?.ErrorCode); return Page(); } + [DisableConcurrentExecution(timeoutInSeconds: 120)] public async Task OnPostUploadFrontEnd(CancellationToken cancellationToken) { @@ -368,8 +401,8 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk TempData["Message"] = "فرآیند Deploy شروع شد. لاگ را بررسی کنید."; return RedirectToPage(); } - return Forbid(); + return Forbid(); } /// @@ -395,13 +428,10 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk { contractingPartyIdList.Add(employer.Employer.ContractingPartyId); } - } if (contractingPartyIdList.Count > 0) { - - if (contractingPartyIdList.Count == 1) { workshop.AddContractingPartyId(contractingPartyIdList[0]); @@ -422,7 +452,6 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk ViewData["message"] = "آی دی های طرف حساب اضافه شد"; return Page(); - } /// @@ -441,8 +470,8 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk var content = System.IO.File.ReadAllText(logPath, Encoding.UTF8); return Content(content); } - return Content("شما مجاز به دیدن لاگ نیستید"); + return Content("شما مجاز به دیدن لاگ نیستید"); } @@ -1055,7 +1084,7 @@ namespace ServiceHost.Areas.AdminNew.Pages.Company.AndroidApk x.PersonnelCount, x.Price, x.InstitutionContractWorkshopGroupId, group, - x.WorkshopId.Value,x.id); + x.WorkshopId.Value, x.id); entity.SetEmployers(x.Employers.Select(e => e.EmployerId).ToList()); return entity;