ProgrmmaagerUserAccount completed

This commit is contained in:
SamSys
2025-11-27 10:48:03 +03:30
parent 86ac300e00
commit 16b04fc75c
13 changed files with 769 additions and 359 deletions

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using AccountManagement.Application.Contracts.Role;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace AccountManagement.Application.Contracts.Account;
@@ -40,4 +41,15 @@ public class CreateAccount
/// آیا کاربر در پروگرام منیجر فعالیت مبکند؟
/// </summary>
public bool IsProgramManagerUser { get; set; }
/// <summary>
/// لیست نقش های پروگرام منیجر
/// </summary>
public List<long> UserRoles { get; set; }
/// <summary>
/// لیست نقشهای موجود در پروگرام منیجر
/// </summary>
public SelectList RoleList { get; set; }
}

View File

@@ -1,6 +1,9 @@
namespace AccountManagement.Application.Contracts.Account;
using System.Collections.Generic;
namespace AccountManagement.Application.Contracts.Account;
public class EditAccount : CreateAccount
{
public long Id { get; set; }
}

View File

@@ -5,5 +5,7 @@ public record ApiResponse
public bool isSuccess { get; set; }
public string errorMessage { get; set; }
public ErrorType ErrorType { get; set; }
}

View File

@@ -1,3 +1,7 @@
namespace AccountManagement.Application.Contracts.ProgramManagerApiResult;
using System.Collections.Generic;
public record CreateProgramManagerUser(string FullName, string UserName, string Password, string Mobile, string Email, long? AccountId);
namespace AccountManagement.Application.Contracts.ProgramManagerApiResult;
public record CreateProgramManagerUser(string FullName, string UserName, string Password, string Mobile, string Email, long? AccountId, List<long> Roles);
public record EditUserCommand(string FullName, string UserName, string Mobile, long AccountId, List<long> Roles, bool IsActive);

View File

@@ -1,4 +1,5 @@
using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Collections.Generic;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace AccountManagement.Application.Contracts.ProgramManagerApiResult;
@@ -49,4 +50,6 @@ public record SingleUserData
/// ای دی اکانت کاربر در گزارشگیر
/// </summary>
public long? accountId { get; set; }
public List<long> Roles { get; set; }
}

View File

@@ -101,7 +101,7 @@ public class AccountApplication : IAccountApplication
var path = $"profilePhotos";
var picturePath = _fileUploader.Upload(command.ProfilePhoto, path);
editAccount.EditClient(command.Fullname,command.Username,command.Mobile,picturePath,command.Email,command.NationalCode);
editAccount.EditClient(command.Fullname, command.Username, command.Mobile, picturePath, command.Email, command.NationalCode);
_accountRepository.SaveChanges();
return opreation.Succcedded();
}
@@ -165,10 +165,11 @@ public class AccountApplication : IAccountApplication
password,
command.Mobile,
command.Email,
account.id
account.id,
command.UserRoles
);
var url = "api/user";
var url = "api/user/create";
var key = SecretKeys.ProgramManagerInternalApi;
var response = InternalApiCaller.PostAsync<CreateProgramManagerUser, ApiResponse>(
@@ -204,7 +205,7 @@ public class AccountApplication : IAccountApplication
return opreation.Failed("پر کردن تمامی فیلدها الزامی است");
if (_accountRepository.Exists(x => x.Username == command.Username))
return opreation.Failed("نام کاربری تکراری است");
if (_accountRepository.Exists(x => x.Mobile == command.Mobile && x.IsActiveString =="true"))
if (_accountRepository.Exists(x => x.Mobile == command.Mobile && x.IsActiveString == "true"))
return opreation.Failed("مقادیر وارد شده تکراری است");
@@ -222,11 +223,11 @@ public class AccountApplication : IAccountApplication
// break;
//}
var password = _passwordHasher.Hash(command.Password);
var register =new Account(command.Fullname,command.Username, password, command.Mobile, command.NationalCode);
var register = new Account(command.Fullname, command.Username, password, command.Mobile, command.NationalCode);
_accountRepository.Create(register);
_accountRepository.SaveChanges();
return opreation.Succcedded(register.id,message: "ثبت نام شما با موفقیت انجام شد");
return opreation.Succcedded(register.id, message: "ثبت نام شما با موفقیت انجام شد");
}
public OperationResult Edit(EditAccount command)
@@ -243,8 +244,97 @@ public class AccountApplication : IAccountApplication
var roleName = _roleRepository.GetDetails(command.RoleId);
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);
_accountRepository.SaveChanges();
var key = SecretKeys.ProgramManagerInternalApi;
var apiResult = InternalApiCaller.GetAsync<SingleUserResponseResult>(
$"api/user/{account.id}",
key
);
//اگر کاربر در پروگرام منیجر قبلا ایجاد شده
if (apiResult.Success && apiResult.Result.Data.accountId == account.id)
{
if (!command.UserRoles.Any())
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.Result.isSuccess)
{
_unitOfWork.RollbackAccountContext();
return operation.Failed(response.Error);
}
}
else //اگر کاربر قبلا ایجاد نشده
{
//اگر تیک فعالیت در پروگرام منیجر روشن بود
if (command.IsProgramManagerUser)
{
if (!command.UserRoles.Any())
return operation.Failed("حداقل یک نقش باید انتخاب شود");
var parameters = new CreateProgramManagerUser(
command.Fullname,
command.Username,
account.Password,
command.Mobile,
command.Email,
account.id,
command.UserRoles
);
var url = "api/user/Create";
var response = InternalApiCaller.PostAsync<CreateProgramManagerUser, ApiResponse>(
url,
key,
parameters
);
if (!response.Success)
{
_unitOfWork.RollbackAccountContext();
return operation.Failed(response.Error);
}
if (!response.Result.isSuccess)
{
_unitOfWork.RollbackAccountContext();
return operation.Failed(response.Error);
}
}
}
_unitOfWork.CommitAccountContext();
return operation.Succcedded();
}
@@ -330,7 +420,7 @@ public class AccountApplication : IAccountApplication
var mobile = string.IsNullOrWhiteSpace(cameraAccount.Mobile) ? " " : cameraAccount.Mobile;
var authViewModel = new CameraAuthViewModel(cameraAccount.id, cameraAccount.WorkshopId,
cameraAccount.Username, mobile, cameraAccount.WorkshopName, cameraAccount.AccountId,cameraAccount.IsActiveSting);
cameraAccount.Username, mobile, cameraAccount.WorkshopName, cameraAccount.AccountId, cameraAccount.IsActiveSting);
if (cameraAccount.IsActiveSting == "true")
{
_authHelper.CameraSignIn(authViewModel);
@@ -478,7 +568,7 @@ public class AccountApplication : IAccountApplication
return _accountRepository.GetByUserNameAndId(id, username);
}
public async Task <OperationResult> SetVerifyCode(string phone, long id)
public async Task<OperationResult> SetVerifyCode(string phone, long id)
{
var operation = new OperationResult();
var account = _accountRepository.Get(id);
@@ -550,7 +640,7 @@ public class AccountApplication : IAccountApplication
_authHelper.SignOut();
var authViewModel = new AuthViewModel(account.id, account.RoleId, account.Fullname
, account.Username, account.Mobile, account.ProfilePhoto, permissions, account.RoleName, "false", "true",null);
, account.Username, account.Mobile, account.ProfilePhoto, permissions, account.RoleName, "false", "true", null);
var workshopList = _workshopRepository.GetWorkshopsByClientAccountId(account.id).Select(x => new WorkshopClaim
{
PersonnelCount = x.PersonnelCount,
@@ -607,7 +697,7 @@ public class AccountApplication : IAccountApplication
public AccountLeftWorkViewModel WorkshopList(long accountId)
{
string fullname = this._accountRepository.GetById(accountId).Fullname;
List<WorkshopAccountlistViewModel> source =_accountLeftworkRepository.WorkshopList(accountId);
List<WorkshopAccountlistViewModel> source = _accountLeftworkRepository.WorkshopList(accountId);
List<long> userWorkshopIds = source.Select(x => x.WorkshopId).ToList();
List<WorkshopSelectList> allWorkshops = this._accountLeftworkRepository.GetAllWorkshops();
List<AccountViewModel> accountSelectList = this._accountRepository.GetAdminAccountSelectList();

View File

@@ -6,6 +6,7 @@ using System.Linq;
using AccountManagement.Application.Contracts.ProgramManagerApiResult;
using AccountManagement.Domain.InternalApiCaller;
using Company.Domain._common;
using AccountManagement.Application.Contracts.Ticket;
namespace AccountManagement.Application;
@@ -56,7 +57,7 @@ public class RoleApplication : IRoleApplication
if (!response.Success)
{
_unitOfWork.RollbackAccountContext();
return operation.Failed(response.Error);
return operation.Failed("ارتباط با اپلیکیش پروگرام منیجر برقرار نشد");
}
if (!response.Result.isSuccess)
@@ -93,8 +94,32 @@ public class RoleApplication : IRoleApplication
_unitOfWork.BeginAccountContext();
role.Edit(command.Name, permissions);
_roleRepository.SaveChanges();
var key = SecretKeys.ProgramManagerInternalApi;
var pmPermissions = command.PmPermissions.Where(x => x > 0).ToList();
//یافتن نقش در پروگرام منیجر
var apiResult = InternalApiCaller.GetAsync<RoleResponse>(
"api/role",
key,
new Dictionary<string, object>
{
{ "RoleName", "" },
{ "GozareshgirRoleId", command.Id}
}
);
if (apiResult.Success)
{
if (apiResult.Result.isSuccess)
{
//اگر این نقش در پروگرام منیجر وجود داشت ویرایش کن
if (apiResult.Result.data.role.Any())
{
var parameters = new CreateProgramManagerRole
{
RoleName = command.Name,
@@ -104,7 +129,7 @@ public class RoleApplication : IRoleApplication
};
var url = "api/role/edit";
var key = SecretKeys.ProgramManagerInternalApi;
var response = InternalApiCaller.PostAsync<CreateProgramManagerRole, ApiResponse>(
url,
@@ -116,7 +141,7 @@ public class RoleApplication : IRoleApplication
if (!response.Success)
{
_unitOfWork.RollbackAccountContext();
return operation.Failed(response.Error);
return operation.Failed("ارتباط با اپلیکیش پروگرام منیجر برقرار نشد");
}
if (!response.Result.isSuccess)
@@ -124,6 +149,64 @@ public class RoleApplication : IRoleApplication
_unitOfWork.RollbackAccountContext();
return operation.Failed(response.Result.errorMessage);
}
}
else //اگر نقش در پروگرام منیجر وجود نداشت
{
//اگر تیک پرمیشن های پروگرام منیجر زده شده
//این نقش را سمت پروگرام منیجر بساز
if (pmPermissions.Any())
{
var parameters = new CreateProgramManagerRole
{
RoleName = command.Name,
Permissions = pmPermissions,
GozareshgirRoleId = role.id
};
var url = "api/role";
var response = InternalApiCaller.PostAsync<CreateProgramManagerRole, ApiResponse>(
url,
key,
parameters
);
if (!response.Success)
{
_unitOfWork.RollbackAccountContext();
return operation.Failed("ارتباط با اپلیکیش پروگرام منیجر برقرار نشد");
}
if (!response.Result.isSuccess)
{
_unitOfWork.RollbackAccountContext();
return operation.Failed(response.Result.errorMessage);
}
}
}
}
else
{
_unitOfWork.RollbackAccountContext();
return operation.Failed("ارتباط با اپلیکیش پروگرام منیجر برقرار نشد");
}
}
else
{
_unitOfWork.RollbackAccountContext();
return operation.Failed("ارتباط با اپلیکیش پروگرام منیجر برقرار نشد");
}

View File

@@ -126,14 +126,32 @@
<div class="row">
<div>
<span>آیا کاربر در پروگرام منیجر هم فعالیت میکند؟</span>
<div class="col-md-6">
<div class="row"></div>
<div class="form-group" style="margin: 29px 7px 0px;">
<span> فعالیت کاربر در پروگرام منیجر </span>
<span>&nbsp;</span>
<label class="switch">
<input id="checkAll" asp-for="IsProgramManagerUser" type="checkbox" />
<input id="checkAll" asp-for="IsProgramManagerUser" type="checkbox"/>
<span class="slider round"></span>
</label>
</div>
</div>
<div class="col-md-6">
<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>
</select>
<span asp-validation-for="UserRoles" class="error"></span>
</div>
</div>
</div>
</div>
@@ -145,3 +163,30 @@
<button type="button" class="btn btn-default btn-rounded waves-effect waves-light m-b-5" data-dismiss="modal">بستن فرم</button>
</div>
</form>
<script>
$(document).ready(function () {
$("#checkAll").change(function () {
$("#hiddenRoleIds").empty();
if ($(this).is(":checked")) {
$(".select-city").removeAttr("disabled");
} else {
$(".select-city").attr("disabled", "disabled");
}
});
});
</script>

View File

@@ -47,7 +47,16 @@
transform: translateX(22px);
}
select.form-control[multiple] {
height: auto !important;
padding: .375rem .75rem !important;
}
</style>
string disable = "disabled=\"disabled\"";
}
<div class="modal-header">
@@ -121,23 +130,90 @@
<div class="row">
<div>
<span>آیا کاربر در پروگرام منیجر هم فعالیت میکند؟</span>
<div class="col-md-6">
<div class="row"></div>
<div class="form-group" style="margin: 29px 7px 0px;">
<span> فعالیت کاربر در پروگرام منیجر </span>
<span>&nbsp;</span>
<label class="switch">
<input id="checkAll" asp-for="IsProgramManagerUser" type="checkbox" />
<input id="editcheckAll" asp-for="IsProgramManagerUser" type="checkbox"/>
<span class="slider round"></span>
</label>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label asp-for="UserRoles"> نقش در پروگرام منیجر </label>
@if (Model.IsProgramManagerUser)
{
<select class="form-control select-city editSelect" multiple="multiple" asp-for="UserRoles" asp-items="Model.RoleList">
<option value="0"></option>
</select>
}
else
{
<select disabled="disabled" class="form-control select-city editSelect" multiple="multiple" asp-for="UserRoles" asp-items="Model.RoleList">
<option value="0"></option>
</select>
}
<span asp-validation-for="UserRoles" class="error"></span>
</div>
</div>
</div>
</div>
</div>
<input type="hidden" asp-for="Id" value="@Model.Id"/>
<div id="edithiddenRoleIds"></div>
<div class="modal-footer">
<button type="submit" class="btn btn-success btn-rounded waves-effect waves-light m-b-5"> ثبت تغییرات </button>
<button type="button" class="btn btn-default btn-rounded waves-effect waves-light m-b-5" data-dismiss="modal">بستن فرم</button>
</div>
</form>
<script>
$(document).ready(function () {
$("#editcheckAll").change(function () {
var userRole= @Html.Raw(System.Text.Json.JsonSerializer.Serialize(Model.UserRoles));
$("#edithiddenRoleIds").empty();
if ($(this).is(":checked")) {
$(".editSelect").removeAttr("disabled");
} else {
userRole.forEach(record => {
$("#edithiddenRoleIds").append(
`<input type="hidden" name="UserRoles" value="${record}" />`
);
});
$(".editSelect").attr("disabled", "disabled");
}
});
});
</script>

View File

@@ -553,6 +553,16 @@
<script src="~/adminTheme/assets/datatables/jquery.dataTables.min.js"></script>
<script src="~/adminTheme/assets/datatables/dataTables.bootstrap.js"></script>
<script src="~/js/signalr/dist/browser/signalr.js"></script>
<script src="~/lib/select2/js/select2.js"></script>
<script src="~/lib/select2/js/i18n/fa.js"></script>
<script>
$(document).ready(function () {
$(".select-city").select2({
language: "fa",
dir: "rtl"
});
})
</script>
<script>
$(document).ready(function() {
$('#datatable').dataTable({

View File

@@ -56,10 +56,33 @@ public class IndexModel : PageModel
public IActionResult OnGetCreate()
{
var command = new CreateAccount
{
Roles = _roleApplication.List()
};
var key = SecretKeys.ProgramManagerInternalApi;
var response = InternalApiCaller.GetAsync<RoleResponse>(
"api/role",
key,
new Dictionary<string, object>
{
{ "RoleName", "" },
{ "GozareshgirRoleId", "" }
}
);
if (response.Success)
{
if (response.Result.isSuccess)
{
command.RoleList = new SelectList(response.Result.data.role, "id", "roleName");
}
}
return Partial("./Create", command);
}
@@ -108,7 +131,8 @@ public class IndexModel : PageModel
// مثل قبل:
if (result != null && result.isSuccess)
{
account.IsProgramManagerUser = (result.Data.accountId == account.Id);
account.IsProgramManagerUser = (result.Data.accountId == account.Id && result.Data.isActive);
account.UserRoles = apiResult.Result.Data.Roles;
}
else
{
@@ -117,6 +141,26 @@ public class IndexModel : PageModel
var response = InternalApiCaller.GetAsync<RoleResponse>(
"api/role",
key,
new Dictionary<string, object>
{
{ "RoleName", "" },
{ "GozareshgirRoleId", "" }
}
);
if (response.Success)
{
if (response.Result.isSuccess)
{
account.RoleList = new SelectList(response.Result.data.role, "id", "roleName");
}
}

View File

@@ -331,15 +331,50 @@ builder.Services.AddParbad().ConfigureGateways(gateways =>
storage.UseMemoryCache();
});
#region GetHttpContext
var httpContextAccessor = new HttpContextAccessor();
builder.Services.AddSingleton<IHttpContextAccessor>(httpContextAccessor);
#endregion
var app = builder.Build();
app.UseCors("AllowSpecificOrigins");
#region InternalProgarmManagerApi
var baseUrl = builder.Configuration["InternalProgramManagerApi:BaseUrl"];
// بعد از Build:
var host = httpContextAccessor.HttpContext?.Request.Host.Host ?? "";
// مقداردهی BaseUrl
string baseUrl;
if (host.Contains("localhost"))
{
baseUrl = builder.Configuration["InternalApi:Local"];
}
else if (host.Contains("dadmehrg.ir"))
{
baseUrl = builder.Configuration["InternalApi:Dadmehrg"];
}
else if (host.Contains("gozareshgir.ir"))
{
baseUrl = builder.Configuration["InternalApi:Gozareshgir"];
}
else
{
baseUrl = builder.Configuration["InternalApi:Local"]; // fallback
}
// مقداردهی به کلاس Static
InternalApiCaller.SetBaseUrl(baseUrl);
#endregion
#region Mahan

View File

@@ -36,10 +36,13 @@
"IsTestMode": false,
"TestNumbers": []
},
"InternalProgramManagerApi": {
"BaseUrl": "https://localhost:7032"
"InternalApi": {
"Local": "https://localhost:7032",
"Dadmehrg": "https://api.pm.dadmehrg.ir",
"Gozareshgir": "https://api.pm.gozareshgir.ir"
},
"SepehrGateWayTerminalId": 99213700
}