From e89aae1cc9624c13a105fcc9acd3b58eef46e722 Mon Sep 17 00:00:00 2001 From: SamSys Date: Sat, 13 Dec 2025 14:11:41 +0330 Subject: [PATCH] change accountTable --- .../AccountApplication.cs | 322 +++++++++--------- .../AccountAgg/Account.cs | 12 +- .../Repository/AccountRepository.cs | 3 +- .../Pages/Accounts/Account/Create.cshtml | 4 +- .../Pages/Accounts/Account/CreateRole.cshtml | 31 +- .../Admin/Pages/Accounts/Account/Edit.cshtml | 4 +- .../Pages/Accounts/Account/EditRole.cshtml | 33 +- .../Pages/Accounts/Account/Index.cshtml.cs | 26 +- 8 files changed, 227 insertions(+), 208 deletions(-) diff --git a/AccountManagement.Application/AccountApplication.cs b/AccountManagement.Application/AccountApplication.cs index bba09128..c36cea6a 100644 --- a/AccountManagement.Application/AccountApplication.cs +++ b/AccountManagement.Application/AccountApplication.cs @@ -155,7 +155,7 @@ public class AccountApplication : IAccountApplication } var account = new Account(command.Fullname, command.Username, password, command.Mobile, command.RoleId, - picturePath, roleName.Name, "true", "false"); + picturePath, roleName.Name, "true", "false", command.IsProgramManagerUser); _unitOfWork.BeginAccountContext(); @@ -163,64 +163,64 @@ public class AccountApplication : IAccountApplication _accountRepository.Create(account); _accountRepository.SaveChanges(); - if (command.IsProgramManagerUser) - { + //if (command.IsProgramManagerUser) + //{ - try - { - if (_pmUserRepository.Exists(x => x.FullName == command.Fullname)) - { - _unitOfWork.RollbackAccountContext(); - return operation.Failed("نام و خانوادگی تکراری است"); - } + // try + // { + // if (_pmUserRepository.Exists(x => x.FullName == command.Fullname)) + // { + // _unitOfWork.RollbackAccountContext(); + // return operation.Failed("نام و خانوادگی تکراری است"); + // } - if (_pmUserRepository.Exists(x => x.UserName == command.Username)) - { - _unitOfWork.RollbackAccountContext(); - return operation.Failed("نام کاربری تکراری است"); - } + // if (_pmUserRepository.Exists(x => x.UserName == command.Username)) + // { + // _unitOfWork.RollbackAccountContext(); + // return operation.Failed("نام کاربری تکراری است"); + // } - if (_pmUserRepository.Exists(x => !string.IsNullOrWhiteSpace(x.Mobile) && x.Mobile == command.Mobile)) - { - _unitOfWork.RollbackAccountContext(); - return operation.Failed("این شماره همراه قبلا به فرد دیگری اختصاص داده شده است"); - } + // if (_pmUserRepository.Exists(x => !string.IsNullOrWhiteSpace(x.Mobile) && x.Mobile == command.Mobile)) + // { + // _unitOfWork.RollbackAccountContext(); + // return operation.Failed("این شماره همراه قبلا به فرد دیگری اختصاص داده شده است"); + // } - var userRoles = command.UserRoles.Where(x => x > 0).Select(x => new PmRoleUser(x)).ToList(); - var create = new PmUser(command.Fullname, command.Username, command.Password, command.Mobile, - null, account.id, userRoles); - await _pmUserRepository.CreateAsync(create); - await _pmUserRepository.SaveChangesAsync(); - } - catch (Exception e) - { - _unitOfWork.RollbackAccountContext(); - return operation.Failed("خطا در ایجاد کاربر پروگرام منیجر"); - } + // var userRoles = command.UserRoles.Where(x => x > 0).Select(x => new PmRoleUser(x)).ToList(); + // var create = new PmUser(command.Fullname, command.Username, command.Password, command.Mobile, + // null, account.id, userRoles); + // await _pmUserRepository.CreateAsync(create); + // await _pmUserRepository.SaveChangesAsync(); + // } + // catch (Exception e) + // { + // _unitOfWork.RollbackAccountContext(); + // return operation.Failed("خطا در ایجاد کاربر پروگرام منیجر"); + // } - //var url = "api/user/create"; - //var key = SecretKeys.ProgramManagerInternalApi; + // //var url = "api/user/create"; + // //var key = SecretKeys.ProgramManagerInternalApi; - //var response = InternalApiCaller.PostAsync( - // url, - // key, - // parameters - //); + // //var response = InternalApiCaller.PostAsync( + // // url, + // // key, + // // parameters + // //); - //if (!response.Success) - //{ - // _unitOfWork.RollbackAccountContext(); - // return operation.Failed(response.Error); - //} + // //if (!response.Success) + // //{ + // // _unitOfWork.RollbackAccountContext(); + // // return operation.Failed(response.Error); + // //} - //if (!response.Result.isSuccess) - //{ - // _unitOfWork.RollbackAccountContext(); - // return operation.Failed(response.Result.errorMessage); - //} - } + // //if (!response.Result.isSuccess) + // //{ + // // _unitOfWork.RollbackAccountContext(); + // // return operation.Failed(response.Result.errorMessage); + // //} + //} _unitOfWork.CommitAccountContext(); return operation.Succcedded(); @@ -276,148 +276,148 @@ public class AccountApplication : IAccountApplication var path = $"profilePhotos"; var picturePath = _fileUploader.Upload(command.ProfilePhoto, path); _unitOfWork.BeginAccountContext(); - account.Edit(command.Fullname, command.Username, command.Mobile, command.RoleId, picturePath, roleName.Name); + account.Edit(command.Fullname, command.Username, command.Mobile, command.RoleId, picturePath, roleName.Name, command.IsProgramManagerUser); _accountRepository.SaveChanges(); - var key = SecretKeys.ProgramManagerInternalApi; + // var key = SecretKeys.ProgramManagerInternalApi; //var apiResult = InternalApiCaller.GetAsync( // $"api/user/{account.id}", // key //); - var userResult = _pmUserRepository.GetByPmUsertoEditbyAccountId(account.id).GetAwaiter().GetResult(); + // var userResult = _pmUserRepository.GetByPmUsertoEditbyAccountId(account.id).GetAwaiter().GetResult(); //اگر کاربر در پروگرام منیجر قبلا ایجاد شده - if (userResult != null) - { - if (!command.UserRoles.Any()) - { - _unitOfWork.RollbackAccountContext(); - return operation.Failed("حداقل یک نقش باید انتخاب شود"); - } + //if (userResult != null) + //{ + // if (!command.UserRoles.Any()) + // { + // _unitOfWork.RollbackAccountContext(); + // return operation.Failed("حداقل یک نقش باید انتخاب شود"); + // } - try - { + // try + // { - var userRoles = command.UserRoles.Where(x => x > 0).Select(x => new PmRoleUser(x)).ToList(); - userResult.Edit(command.Fullname, command.Username, command.Mobile, userRoles, command.IsProgramManagerUser); - await _pmUserRepository.SaveChangesAsync(); - } - catch (Exception) - { - _unitOfWork.RollbackAccountContext(); - return operation.Failed("خطا در ویرایش کاربر پروگرام منیجر"); - } - //var parameters = new EditUserCommand( - // command.Fullname, - // command.Username, - // command.Mobile, - // account.id, - // command.UserRoles, - // command.IsProgramManagerUser - //); - //var url = "api/user/edit"; - //var response = InternalApiCaller.PostAsync( - // url, - // key, - // parameters - //); + // var userRoles = command.UserRoles.Where(x => x > 0).Select(x => new PmRoleUser(x)).ToList(); + // userResult.Edit(command.Fullname, command.Username, command.Mobile, userRoles, command.IsProgramManagerUser); + // await _pmUserRepository.SaveChangesAsync(); + // } + // catch (Exception) + // { + // _unitOfWork.RollbackAccountContext(); + // return operation.Failed("خطا در ویرایش کاربر پروگرام منیجر"); + // } + // //var parameters = new EditUserCommand( + // // command.Fullname, + // // command.Username, + // // command.Mobile, + // // account.id, + // // command.UserRoles, + // // command.IsProgramManagerUser + // //); + // //var url = "api/user/edit"; + // //var response = InternalApiCaller.PostAsync( + // // url, + // // key, + // // parameters + // //); - //if (!response.Success) - //{ - // _unitOfWork.RollbackAccountContext(); - // return operation.Failed(response.Error); + // //if (!response.Success) + // //{ + // // _unitOfWork.RollbackAccountContext(); + // // return operation.Failed(response.Error); - //} + // //} - //if (!response.Result.isSuccess) - //{ - // _unitOfWork.RollbackAccountContext(); - // return operation.Failed(response.Error); - //} + // //if (!response.Result.isSuccess) + // //{ + // // _unitOfWork.RollbackAccountContext(); + // // return operation.Failed(response.Error); + // //} - } - else //اگر کاربر قبلا ایجاد نشده - { - //اگر تیک فعالیت در پروگرام منیجر روشن بود - if (command.IsProgramManagerUser) - { - if (!command.UserRoles.Any()) - { - _unitOfWork.RollbackAccountContext(); - return operation.Failed("حداقل یک نقش باید انتخاب شود"); - } + //} + //else //اگر کاربر قبلا ایجاد نشده + //{ + // //اگر تیک فعالیت در پروگرام منیجر روشن بود + // if (command.IsProgramManagerUser) + // { + // if (!command.UserRoles.Any()) + // { + // _unitOfWork.RollbackAccountContext(); + // return operation.Failed("حداقل یک نقش باید انتخاب شود"); + // } - if (_pmUserRepository.Exists(x => x.FullName == command.Fullname)) - { - _unitOfWork.RollbackAccountContext(); - return operation.Failed("نام و خانوادگی تکراری است"); - } + // if (_pmUserRepository.Exists(x => x.FullName == command.Fullname)) + // { + // _unitOfWork.RollbackAccountContext(); + // return operation.Failed("نام و خانوادگی تکراری است"); + // } - if (_pmUserRepository.Exists(x => x.UserName == command.Username)) - { - _unitOfWork.RollbackAccountContext(); - return operation.Failed("نام کاربری تکراری است"); - } + // if (_pmUserRepository.Exists(x => x.UserName == command.Username)) + // { + // _unitOfWork.RollbackAccountContext(); + // return operation.Failed("نام کاربری تکراری است"); + // } - if (_pmUserRepository.Exists(x => !string.IsNullOrWhiteSpace(x.Mobile) && x.Mobile == command.Mobile)) - { - _unitOfWork.RollbackAccountContext(); - return operation.Failed("این شماره همراه قبلا به فرد دیگری اختصاص داده شده است"); - } + // if (_pmUserRepository.Exists(x => !string.IsNullOrWhiteSpace(x.Mobile) && x.Mobile == command.Mobile)) + // { + // _unitOfWork.RollbackAccountContext(); + // return operation.Failed("این شماره همراه قبلا به فرد دیگری اختصاص داده شده است"); + // } - try - { - var userRoles = command.UserRoles.Where(x => x > 0).Select(x => new PmRoleUser(x)).ToList(); - var create = new PmUser(command.Fullname, command.Username, account.Password, command.Mobile, - null, account.id, userRoles); - await _pmUserRepository.CreateAsync(create); - await _pmUserRepository.SaveChangesAsync(); - } - catch (Exception) - { + // try + // { + // var userRoles = command.UserRoles.Where(x => x > 0).Select(x => new PmRoleUser(x)).ToList(); + // var create = new PmUser(command.Fullname, command.Username, account.Password, command.Mobile, + // null, account.id, userRoles); + // await _pmUserRepository.CreateAsync(create); + // await _pmUserRepository.SaveChangesAsync(); + // } + // catch (Exception) + // { - _unitOfWork.RollbackAccountContext(); - return operation.Failed("خطا در ویرایش کاربر پروگرام منیجر"); - } + // _unitOfWork.RollbackAccountContext(); + // return operation.Failed("خطا در ویرایش کاربر پروگرام منیجر"); + // } - //var parameters = new CreateProgramManagerUser( - // command.Fullname, - // command.Username, - // account.Password, - // command.Mobile, - // command.Email, - // account.id, - // command.UserRoles - //); + // //var parameters = new CreateProgramManagerUser( + // // command.Fullname, + // // command.Username, + // // account.Password, + // // command.Mobile, + // // command.Email, + // // account.id, + // // command.UserRoles + // //); - //var url = "api/user/Create"; + // //var url = "api/user/Create"; - //var response = InternalApiCaller.PostAsync( - // url, - // key, - // parameters - //); + // //var response = InternalApiCaller.PostAsync( + // // url, + // // key, + // // parameters + // //); - //if (!response.Success) - //{ - // _unitOfWork.RollbackAccountContext(); - // return operation.Failed(response.Error); + // //if (!response.Success) + // //{ + // // _unitOfWork.RollbackAccountContext(); + // // return operation.Failed(response.Error); - //} + // //} - //if (!response.Result.isSuccess) - //{ - // _unitOfWork.RollbackAccountContext(); - // return operation.Failed(response.Error); - //} - } + // //if (!response.Result.isSuccess) + // //{ + // // _unitOfWork.RollbackAccountContext(); + // // return operation.Failed(response.Error); + // //} + // } - } + //} _unitOfWork.CommitAccountContext(); return operation.Succcedded(); @@ -919,7 +919,7 @@ public class AccountApplication : IAccountApplication if (!string.IsNullOrWhiteSpace(command.PhoneNumber)) { - entity.Edit(entity.Fullname, entity.Username, command.PhoneNumber, entity.RoleId, entity.ProfilePhoto, entity.RoleName); + entity.Edit(entity.Fullname, entity.Username, command.PhoneNumber, entity.RoleId, entity.ProfilePhoto, entity.RoleName, false); } _accountRepository.SaveChanges(); return op.Succcedded(); diff --git a/AccountManagement.Domain/AccountAgg/Account.cs b/AccountManagement.Domain/AccountAgg/Account.cs index 253297ba..2b797142 100644 --- a/AccountManagement.Domain/AccountAgg/Account.cs +++ b/AccountManagement.Domain/AccountAgg/Account.cs @@ -25,6 +25,11 @@ namespace AccountManagement.Domain.AccountAgg public string VerifyCode { get; set; } public string IsActiveString { get; private set; } + /// + /// آیا کاربر در پروگرام منیجر فعالیت می کند + /// + public bool IsProgramManagerUser { get; private set; } + #region Mahan public string PositionIsActive { get; private set; } public long? PositionId { get; private set; } @@ -35,7 +40,7 @@ namespace AccountManagement.Domain.AccountAgg public List CameraAccounts { get; private set; } public List AccountLeftWorkList { get; set; } public Account(string fullname, string username, string password, string mobile, - long roleId, string profilePhoto, string roleName, string adminAreaPermission, string clientAriaPermission) + long roleId, string profilePhoto, string roleName, string adminAreaPermission, string clientAriaPermission, bool isProgramManagerUser) { Fullname = fullname; Username = username; @@ -50,6 +55,7 @@ namespace AccountManagement.Domain.AccountAgg RoleName = roleName; AdminAreaPermission = adminAreaPermission; ClientAriaPermission = clientAriaPermission; + IsProgramManagerUser = isProgramManagerUser; IsActiveString = "true"; } @@ -70,18 +76,20 @@ namespace AccountManagement.Domain.AccountAgg public Account() { + ProfilePhoto = " "; } public void Edit(string fullname, string username, string mobile, - long roleId, string profilePhoto, string roleName) + long roleId, string profilePhoto, string roleName, bool isProgramManagerUser) { Fullname = fullname; Username = username; Mobile = mobile; RoleId = roleId; RoleName = roleName; + IsProgramManagerUser = isProgramManagerUser; if (!string.IsNullOrWhiteSpace(profilePhoto)) ProfilePhoto = profilePhoto; } diff --git a/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs index 1947a65b..4e0a4dc4 100644 --- a/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs +++ b/AccountMangement.Infrastructure.EFCore/Repository/AccountRepository.cs @@ -46,7 +46,8 @@ public class AccountRepository : RepositoryBase, IAccountReposito Mobile = x.Mobile, RoleId = x.RoleId, Username = x.Username, - IsActiveString = x.IsActiveString + IsActiveString = x.IsActiveString, + IsProgramManagerUser = x.IsProgramManagerUser, }).FirstOrDefault(x => x.Id == id); } diff --git a/ServiceHost/Areas/Admin/Pages/Accounts/Account/Create.cshtml b/ServiceHost/Areas/Admin/Pages/Accounts/Account/Create.cshtml index 4819c826..23e201b4 100644 --- a/ServiceHost/Areas/Admin/Pages/Accounts/Account/Create.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Accounts/Account/Create.cshtml @@ -142,7 +142,7 @@
-
+ @*
- `); - pmIndex++; - } else { $("#hiddenInput").append(` `); normalIndex++; - } + // const isPm = chk.hasAttribute("data-pm"); + + // if (isPm) { + // $("#hiddenInput").append(` + // + // `); + // pmIndex++; + // } else { + // $("#hiddenInput").append(` + // + // `); + // normalIndex++; + // } }); diff --git a/ServiceHost/Areas/Admin/Pages/Accounts/Account/Edit.cshtml b/ServiceHost/Areas/Admin/Pages/Accounts/Account/Edit.cshtml index cfcf1bab..c3918b66 100644 --- a/ServiceHost/Areas/Admin/Pages/Accounts/Account/Edit.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Accounts/Account/Edit.cshtml @@ -146,7 +146,7 @@
-
+@*
@if (Model.IsProgramManagerUser) @@ -165,7 +165,7 @@ -
+
*@
diff --git a/ServiceHost/Areas/Admin/Pages/Accounts/Account/EditRole.cshtml b/ServiceHost/Areas/Admin/Pages/Accounts/Account/EditRole.cshtml index da948964..8f0688a9 100644 --- a/ServiceHost/Areas/Admin/Pages/Accounts/Account/EditRole.cshtml +++ b/ServiceHost/Areas/Admin/Pages/Accounts/Account/EditRole.cshtml @@ -1363,30 +1363,35 @@ function saveRole() { const checks = document.querySelectorAll("input.check-btn"); - let pmIndex = 0; + //let pmIndex = 0; let normalIndex = 0; $("#hiddenInput").empty(); // مهم!! قبل از اضافه‌کردن، خالی کن checks.forEach(chk => { - - const isPm = chk.hasAttribute("data-pm"); - - if (isPm) { - $("#hiddenInput").append(` - - `); - pmIndex++; - } else { - $("#hiddenInput").append(` + $("#hiddenInput").append(` `); normalIndex++; - } + // const isPm = chk.hasAttribute("data-pm"); + + // if (isPm) { + // $("#hiddenInput").append(` + // + // `); + // pmIndex++; + // } else { + // $("#hiddenInput").append(` + // + // `); + // normalIndex++; + // } }); diff --git a/ServiceHost/Areas/Admin/Pages/Accounts/Account/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Accounts/Account/Index.cshtml.cs index e4597d4f..f7f192db 100644 --- a/ServiceHost/Areas/Admin/Pages/Accounts/Account/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Accounts/Account/Index.cshtml.cs @@ -121,22 +121,22 @@ public class IndexModel : PageModel //); - var result = _accountApplication.GetPmUserByAccountId(account.Id).GetAwaiter().GetResult(); + //var result = _accountApplication.GetPmUserByAccountId(account.Id).GetAwaiter().GetResult(); - // مثل قبل: - if (result != null) - { - account.IsProgramManagerUser = (result.AccountId== account.Id && result.IsActive); - account.UserRoles = result.Roles; - } - else - { - account.IsProgramManagerUser = false; - } + //// مثل قبل: + //if (result != null) + //{ + // account.IsProgramManagerUser = (result.AccountId== account.Id && result.IsActive); + // account.UserRoles = result.Roles; + //} + //else + //{ + // account.IsProgramManagerUser = false; + //} - var pmRolseSelectList = _roleApplication.GetPmRoleList(null).GetAwaiter().GetResult(); - account.RoleList = pmRolseSelectList; + //var pmRolseSelectList = _roleApplication.GetPmRoleList(null).GetAwaiter().GetResult(); + //account.RoleList = pmRolseSelectList; //var response = InternalApiCaller.GetAsync( // "api/role",