change accountTable

This commit is contained in:
SamSys
2025-12-13 14:11:41 +03:30
parent 9469a5f76e
commit e89aae1cc9
8 changed files with 227 additions and 208 deletions

View File

@@ -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<CreateProgramManagerUser, ApiResponse>(
// url,
// key,
// parameters
//);
// //var response = InternalApiCaller.PostAsync<CreateProgramManagerUser, ApiResponse>(
// // 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<SingleUserResponseResult>(
// $"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<EditUserCommand, ApiResponse>(
// 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<EditUserCommand, ApiResponse>(
// // 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<CreateProgramManagerUser, ApiResponse>(
// url,
// key,
// parameters
//);
// //var response = InternalApiCaller.PostAsync<CreateProgramManagerUser, ApiResponse>(
// // 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();

View File

@@ -25,6 +25,11 @@ namespace AccountManagement.Domain.AccountAgg
public string VerifyCode { get; set; }
public string IsActiveString { get; private set; }
/// <summary>
/// آیا کاربر در پروگرام منیجر فعالیت می کند
/// </summary>
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<CameraAccount> CameraAccounts { get; private set; }
public List<AccountLeftWork> 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;
}

View File

@@ -46,7 +46,8 @@ public class AccountRepository : RepositoryBase<long, Account>, IAccountReposito
Mobile = x.Mobile,
RoleId = x.RoleId,
Username = x.Username,
IsActiveString = x.IsActiveString
IsActiveString = x.IsActiveString,
IsProgramManagerUser = x.IsProgramManagerUser,
}).FirstOrDefault(x => x.Id == id);
}

View File

@@ -142,7 +142,7 @@
</div>
<div class="col-md-6">
<div class="form-group">
@* <div class="form-group">
<label asp-for="UserRoles" > نقش در پروگرام منیجر </label>
<select disabled="disabled" class="form-control select-city" multiple="multiple" asp-for="UserRoles" asp-items="Model.RoleList">
<option value="0"></option>
@@ -150,7 +150,7 @@
<span asp-validation-for="UserRoles" class="error"></span>
</div>
</div> *@
</div>
</div>
</div>

View File

@@ -1309,30 +1309,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(`
<input class="item1" type="hidden"
name="PmPermissions[${pmIndex}]"
value="${chk.checked ? chk.value : 0}">
`);
pmIndex++;
} else {
$("#hiddenInput").append(`
<input class="item1" type="hidden"
name="Permissions[${normalIndex}]"
value="${chk.checked ? chk.value : 0}">
`);
normalIndex++;
}
// const isPm = chk.hasAttribute("data-pm");
// if (isPm) {
// $("#hiddenInput").append(`
// <input class="item1" type="hidden"
// name="PmPermissions[${pmIndex}]"
// value="${chk.checked ? chk.value : 0}">
// `);
// pmIndex++;
// } else {
// $("#hiddenInput").append(`
// <input class="item1" type="hidden"
// name="Permissions[${normalIndex}]"
// value="${chk.checked ? chk.value : 0}">
// `);
// normalIndex++;
// }
});

View File

@@ -146,7 +146,7 @@
</div>
<div class="col-md-6">
<div class="form-group">
@* <div class="form-group">
<label asp-for="UserRoles"> نقش در پروگرام منیجر </label>
@if (Model.IsProgramManagerUser)
@@ -165,7 +165,7 @@
<span asp-validation-for="UserRoles" class="error"></span>
</div>
</div> *@
</div>
</div>
</div>

View File

@@ -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(`
<input class="item1" type="hidden"
name="PmPermissions[${pmIndex}]"
value="${chk.checked ? chk.value : 0}">
`);
pmIndex++;
} else {
$("#hiddenInput").append(`
$("#hiddenInput").append(`
<input class="item1" type="hidden"
name="Permissions[${normalIndex}]"
value="${chk.checked ? chk.value : 0}">
`);
normalIndex++;
}
// const isPm = chk.hasAttribute("data-pm");
// if (isPm) {
// $("#hiddenInput").append(`
// <input class="item1" type="hidden"
// name="PmPermissions[${pmIndex}]"
// value="${chk.checked ? chk.value : 0}">
// `);
// pmIndex++;
// } else {
// $("#hiddenInput").append(`
// <input class="item1" type="hidden"
// name="Permissions[${normalIndex}]"
// value="${chk.checked ? chk.value : 0}">
// `);
// normalIndex++;
// }
});

View File

@@ -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<RoleResponse>(
// "api/role",