From 7ab83c73aab0886f03685affd440c55571d80066 Mon Sep 17 00:00:00 2001 From: SamSys Date: Sun, 20 Apr 2025 18:12:47 +0330 Subject: [PATCH] institutionContract createClinetAccount bug fixed --- .../Account/IAccountApplication.cs | 7 ++ .../AccountApplication.cs | 9 +- .../AccountAgg/IAccountRepository.cs | 7 ++ .../Repository/AccountRepository.cs | 5 ++ .../InstitutionContracts/Index.cshtml.cs | 84 +++++++++++++++++-- 5 files changed, 103 insertions(+), 9 deletions(-) diff --git a/AccountManagement.Application.Contracts/Account/IAccountApplication.cs b/AccountManagement.Application.Contracts/Account/IAccountApplication.cs index 52161779..539382a9 100644 --- a/AccountManagement.Application.Contracts/Account/IAccountApplication.cs +++ b/AccountManagement.Application.Contracts/Account/IAccountApplication.cs @@ -55,4 +55,11 @@ public interface IAccountApplication #endregion OperationResult DirectCameraLogin(long cameraAccountId); + + /// + /// چک میکند که آیا اکانتی با این نام کاربری وجود دارد یا نه + /// + /// + /// + public bool CheckExistClientAccount(string userName); } \ No newline at end of file diff --git a/AccountManagement.Application/AccountApplication.cs b/AccountManagement.Application/AccountApplication.cs index 6475af0e..2ee723f4 100644 --- a/AccountManagement.Application/AccountApplication.cs +++ b/AccountManagement.Application/AccountApplication.cs @@ -549,7 +549,8 @@ public class AccountApplication : IAccountApplication return operation.Succcedded(2); } - public AccountLeftWorkViewModel WorkshopList(long accountId) + + public AccountLeftWorkViewModel WorkshopList(long accountId) { string fullname = this._accountRepository.GetById(accountId).Fullname; List source =_accountLeftworkRepository.WorkshopList(accountId); @@ -785,4 +786,10 @@ public class AccountApplication : IAccountApplication //} #endregion + + public bool CheckExistClientAccount(string userName) + { + return _accountRepository.CheckExistClientAccount(userName); + } + } \ No newline at end of file diff --git a/AccountManagement.Domain/AccountAgg/IAccountRepository.cs b/AccountManagement.Domain/AccountAgg/IAccountRepository.cs index 6279567f..f7fa7957 100644 --- a/AccountManagement.Domain/AccountAgg/IAccountRepository.cs +++ b/AccountManagement.Domain/AccountAgg/IAccountRepository.cs @@ -33,6 +33,13 @@ namespace AccountManagement.Domain.AccountAgg List GetAccountsToEditWorkshop(long workshopId); + /// + /// چک میکند که اکانتی با این ام کاربری وجود دارد یا نه + /// + /// + /// + public bool CheckExistClientAccount(string userName); + } } diff --git a/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs index 60d857aa..ae87a101 100644 --- a/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs +++ b/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs @@ -332,4 +332,9 @@ public class AccountRepository : RepositoryBase, IAccountReposito #endregion + + public bool CheckExistClientAccount(string userName) + { + return _context.Accounts.Any(x => x.Username == userName); + } } \ No newline at end of file diff --git a/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml.cs index 209d12b6..c6267b2f 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Company/InstitutionContracts/Index.cshtml.cs @@ -429,10 +429,21 @@ public class IndexModel : PageModel } public IActionResult OnPostEdit(EditInstitutionContract command) - { - //if (string.IsNullOrWhiteSpace(command.HasValueAddedTax)) - // command.HasValueAddedTax = "false"; - var result = _institutionContract.Edit(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 = _institutionContract.Edit(command); var contractingPartyId = _institutionContract.GetDetails(result.SendId); var counter = command.ContactInformationList.Count; var getOldContarct = _institutionContract.NewSearch(new InstitutionContractSearchModel() @@ -484,7 +495,29 @@ public class IndexModel : PageModel 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) + _institutionContract.CreateContractingPartyAccount(command.ContractingPartyId, res.SendId); + } + } //Thread.Sleep(500); //for (int i = 0; i <= counter - 1; i++) //{ @@ -661,8 +694,22 @@ public class IndexModel : PageModel } public IActionResult OnPostExtension(CreateInstitutionContract command) - { - var counter = command.ContactInformationList.Count; + { + 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("تعیین شماره همراه با سمت طرف قرارداد اجباریست")); + + + var counter = command.ContactInformationList.Count; var result = _institutionContract.Extension(command); @@ -725,7 +772,28 @@ public class IndexModel : PageModel 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) + _institutionContract.CreateContractingPartyAccount(command.ContractingPartyId, res.SendId); + } + } } return new JsonResult(result);