edit role completed

This commit is contained in:
SamSys
2025-11-26 13:37:04 +03:30
parent 90a420c8c5
commit 86ac300e00
21 changed files with 801 additions and 152 deletions

View File

@@ -1,21 +0,0 @@
namespace AccountManagement.Application.Contracts.Account;
public record CreateUserApiResponse
{
public bool isSuccess { get; set; }
public string? errorMessage { get; set; }
public ErrorType ErrorType { get; set; }
}
public record CreateProgramManagerUser(string FullName, string UserName, string Password, string Mobile, string? Email, long? AccountId);
public enum ErrorType
{
None,
BadRequest,
NotFound,
Unauthorized,
Validation,
InternalServerError
}

View File

@@ -0,0 +1,9 @@
namespace AccountManagement.Application.Contracts.ProgramManagerApiResult;
public record ApiResponse
{
public bool isSuccess { get; set; }
public string errorMessage { get; set; }
public ErrorType ErrorType { get; set; }
}

View File

@@ -0,0 +1,22 @@
using System.Collections.Generic;
namespace AccountManagement.Application.Contracts.ProgramManagerApiResult;
public record CreateProgramManagerRole
{
/// <summary>
/// نام نقش
/// </summary>
public string RoleName { get; set; }
/// <summary>
/// کدهای دسترسی
/// </summary>
public List<int> Permissions { get; set; }
/// <summary>
/// آی دی اکانت گزارشگیر
/// </summary>
public long? GozareshgirRoleId { get; set; }
};

View File

@@ -0,0 +1,3 @@
namespace AccountManagement.Application.Contracts.ProgramManagerApiResult;
public record CreateProgramManagerUser(string FullName, string UserName, string Password, string Mobile, string Email, long? AccountId);

View File

@@ -0,0 +1,11 @@
namespace AccountManagement.Application.Contracts.ProgramManagerApiResult;
public enum ErrorType
{
None,
BadRequest,
NotFound,
Unauthorized,
Validation,
InternalServerError
}

View File

@@ -0,0 +1,22 @@
using System.Collections.Generic;
namespace AccountManagement.Application.Contracts.ProgramManagerApiResult;
public class RoleResponse
{
public bool isSuccess { get; set; }
public RolesData data { get; set; }
}
public class RolesData
{
public List<RoleList> role { get; set; }
}
public class RoleList
{
public int id { get; set; }
public string roleName { get; set; }
public int gozareshgirRoleId { get; set; }
public List<int> permissions { get; set; }
}

View File

@@ -0,0 +1,52 @@
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace AccountManagement.Application.Contracts.ProgramManagerApiResult;
public record SingleUserResponseResult
{
public bool isSuccess { get; set; }
public SingleUserData Data { get; set; }
};
public record SingleUserData
{
public long id { get; set; }
/// <summary>
/// نام و نام خانوادگی
/// </summary>
public string fullName { get; set; }
/// <summary>
/// نام کاربری
/// </summary>
public string userName { get; set; }
/// <summary>
/// مسیر عکس پروفایل
/// </summary>
public string profilePhotoPath { get; set; }
/// <summary>
/// شماره موبایل
/// </summary>
public string mobile { get; set; }
/// <summary>
/// فعال/غیر فعال بودن یوزر
/// </summary>
public bool isActive { get; set; }
/// <summary>
/// گذرواژه
/// </summary>
public string password { get; set; }
/// <summary>
/// ای دی اکانت کاربر در گزارشگیر
/// </summary>
public long? accountId { get; set; }
}

View File

@@ -9,6 +9,10 @@ namespace AccountManagement.Application.Contracts.Role
[Required(ErrorMessage = ValidationMessages.IsRequired)]
public string Name { get; set; }
public List<int> Permissions { get; set; }
/// <summary>
/// لیست پرمیشن های پروگرام منیجر
/// </summary>
public List<int> PmPermissions { get; set; }
}
}

View File

@@ -29,6 +29,8 @@ using Company.Domain.WorkshopSubAccountAgg;
using Newtonsoft.Json;
using Microsoft.EntityFrameworkCore;
using Company.Domain._common;
using AccountManagement.Domain.InternalApiCaller;
using AccountManagement.Application.Contracts.ProgramManagerApiResult;
//using AccountManagement.Domain.RoleAgg;
@@ -149,7 +151,9 @@ public class AccountApplication : IAccountApplication
var account = new Account(command.Fullname, command.Username, password, command.Mobile, command.RoleId,
picturePath, roleName.Name, "true", "false");
_unitOfWork.Begin();
_unitOfWork.BeginAccountContext();
_accountRepository.Create(account);
_accountRepository.SaveChanges();
@@ -164,42 +168,29 @@ public class AccountApplication : IAccountApplication
account.id
);
var url = "api/user";
var key = SecretKeys.ProgramManagerInternalApi;
var client = new HttpClient();
var url = "https://localhost:7032/api/user";
var response = InternalApiCaller.PostAsync<CreateProgramManagerUser, ApiResponse>(
url,
key,
parameters
);
// ساخت درخواست درست
var request = new HttpRequestMessage(HttpMethod.Post, url);
request.Headers.Add("X-INTERNAL-KEY", key);
// تبدیل مدل به JSON در Body
var json = JsonConvert.SerializeObject(parameters);
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
var response = client.SendAsync(request).GetAwaiter().GetResult();
var success = response.IsSuccessStatusCode;
if (success)
if (!response.Success)
{
var res = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
var result = JsonConvert.DeserializeObject<CreateUserApiResponse>(res);
if (!result.isSuccess)
{
_unitOfWork.Rollback();
return operation.Failed(result.errorMessage);
}
//Console.WriteLine(result.Data.accountId + " " + result.Data.mobile);
_unitOfWork.RollbackAccountContext();
return operation.Failed(response.Error);
}
else
if (!response.Result.isSuccess)
{
_unitOfWork.Rollback();
return operation.Failed("خطا در ایجاد کاربر پروگرام منیجر");
_unitOfWork.RollbackAccountContext();
return operation.Failed(response.Result.errorMessage);
}
}
_unitOfWork.Commit();
_unitOfWork.CommitAccountContext();
return operation.Succcedded();
}

View File

@@ -2,16 +2,22 @@
using AccountManagement.Application.Contracts.Role;
using AccountManagement.Domain.RoleAgg;
using System.Collections.Generic;
using System.Linq;
using AccountManagement.Application.Contracts.ProgramManagerApiResult;
using AccountManagement.Domain.InternalApiCaller;
using Company.Domain._common;
namespace AccountManagement.Application;
public class RoleApplication : IRoleApplication
{
private readonly IRoleRepository _roleRepository;
private readonly IUnitOfWork _unitOfWork;
public RoleApplication(IRoleRepository roleRepository)
public RoleApplication(IRoleRepository roleRepository, IUnitOfWork unitOfWork)
{
_roleRepository = roleRepository;
_unitOfWork = unitOfWork;
}
public OperationResult Create(CreateRole command)
@@ -19,18 +25,51 @@ public class RoleApplication : IRoleApplication
var operation = new OperationResult();
if (_roleRepository.Exists(x => x.Name == command.Name))
return operation.Failed(ApplicationMessages.DuplicatedRecord);
var permissions = new List<Permission>();
foreach (var code in command.Permissions)
{
if (code > 0)
{
permissions.Add(new Permission(code));
}
}
//command.Permissions.ForEach(code => permissions.Add(new Permission(code)));
var permissions = command.Permissions.Where(x => x > 0).Select(x => new Permission(x)).ToList();
var role = new Role(command.Name, permissions);
_unitOfWork.BeginAccountContext();
_roleRepository.Create(role);
_roleRepository.SaveChanges();
var pmPermissions = command.PmPermissions.Where(x => x > 0).ToList();
if (pmPermissions.Any())
{
var parameters = new CreateProgramManagerRole
{
RoleName = command.Name,
Permissions = pmPermissions,
GozareshgirRoleId = role.id
};
var url = "api/role";
var key = SecretKeys.ProgramManagerInternalApi;
var response = InternalApiCaller.PostAsync<CreateProgramManagerRole, ApiResponse>(
url,
key,
parameters
);
if (!response.Success)
{
_unitOfWork.RollbackAccountContext();
return operation.Failed(response.Error);
}
if (!response.Result.isSuccess)
{
_unitOfWork.RollbackAccountContext();
return operation.Failed(response.Result.errorMessage);
}
}
//command.Permissions.ForEach(code => permissions.Add(new Permission(code)));
_unitOfWork.CommitAccountContext();
return operation.Succcedded();
}
@@ -47,17 +86,47 @@ public class RoleApplication : IRoleApplication
//var permissions = new List<Permission>();
//command.Permissions.ForEach(code => permissions.Add(new Permission(code)));
var permissions = new List<Permission>();
foreach (var code in command.Permissions)
{
if (code > 0)
{
permissions.Add(new Permission(code));
}
}
var permissions = command.Permissions.Where(x => x > 0).Select(x => new Permission(x)).ToList();
_unitOfWork.BeginAccountContext();
role.Edit(command.Name, permissions);
_roleRepository.SaveChanges();
var pmPermissions = command.PmPermissions.Where(x => x > 0).ToList();
var parameters = new CreateProgramManagerRole
{
RoleName = command.Name,
Permissions = pmPermissions,
GozareshgirRoleId = role.id
};
var url = "api/role/edit";
var key = SecretKeys.ProgramManagerInternalApi;
var response = InternalApiCaller.PostAsync<CreateProgramManagerRole, ApiResponse>(
url,
key,
parameters
);
if (!response.Success)
{
_unitOfWork.RollbackAccountContext();
return operation.Failed(response.Error);
}
if (!response.Result.isSuccess)
{
_unitOfWork.RollbackAccountContext();
return operation.Failed(response.Result.errorMessage);
}
return operation.Succcedded();
}

View File

@@ -0,0 +1,155 @@
using Newtonsoft.Json;
using System.Net.Http;
using System.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Configuration;
namespace AccountManagement.Domain.InternalApiCaller;
public class ApiResult<T>
{
public bool Success { get; set; }
public T Result { get; set; }
public string Error { get; set; }
}
public static class InternalApiCaller
{
private static string _baseUrl = "";
public static void SetBaseUrl(string baseUrl)
{
_baseUrl = baseUrl.TrimEnd('/'); // حذف / اضافی
}
/// <summary>
///api post متد
/// </summary>
/// <typeparam name="TRequest"></typeparam>
/// <typeparam name="TResponse"></typeparam>
/// <param name="url"></param>
/// <param name="internalKey"></param>
/// <param name="body"></param>
/// <returns></returns>
public static ApiResult<TResponse> PostAsync<TRequest, TResponse>(
string url,
string internalKey,
TRequest body
)
{
try
{
var client = new HttpClient();
// ساخت URL نهایی
var finalUrl = $"{_baseUrl}/{url.TrimStart('/')}";
var request = new HttpRequestMessage(HttpMethod.Post, finalUrl);
request.Headers.Add("X-INTERNAL-KEY", internalKey);
var json = JsonConvert.SerializeObject(body);
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
var response = client.SendAsync(request).GetAwaiter().GetResult();
if (!response.IsSuccessStatusCode)
{
return new ApiResult<TResponse>
{
Success = false,
Error = $"HTTP Error: {response.StatusCode}"
};
}
var text = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
var deserialized = JsonConvert.DeserializeObject<TResponse>(text);
return new ApiResult<TResponse>
{
Success = true,
Result = deserialized
};
}
catch (Exception ex)
{
return new ApiResult<TResponse>
{
Success = false,
Error = ex.Message
};
}
}
/// <summary>
/// Api Get متد
/// </summary>
/// <typeparam name="TResponse"></typeparam>
/// <param name="url"></param>
/// <param name="internalKey"></param>
/// <param name="parameters"></param>
/// <returns></returns>
public static ApiResult<TResponse> GetAsync<TResponse>(
string url,
string internalKey,
Dictionary<string, object> parameters = null
)
{
try
{
if (parameters != null && parameters.Any())
{
var query = string.Join("&",
parameters
.Where(p => p.Value != null)
.Select(p => $"{p.Key}={p.Value}")
);
url += url.Contains("?") ? "&" + query : "?" + query;
}
// ساخت URL نهایی
var finalUrl = $"{_baseUrl}/{url.TrimStart('/')}";
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, finalUrl);
request.Headers.Add("X-INTERNAL-KEY", internalKey);
var response = client.SendAsync(request).GetAwaiter().GetResult();
if (!response.IsSuccessStatusCode)
{
return new ApiResult<TResponse>
{
Success = false,
Error = $"HTTP Error: {response.StatusCode}"
};
}
var text = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
var deserialized = JsonConvert.DeserializeObject<TResponse>(text);
return new ApiResult<TResponse>
{
Success = true,
Result = deserialized
};
}
catch (Exception ex)
{
return new ApiResult<TResponse>
{
Success = false,
Error = ex.Message
};
}
}
}

View File

@@ -2,7 +2,7 @@
public interface IUnitOfWork
{
void Begin();
void Commit();
void Rollback();
void BeginAccountContext();
void CommitAccountContext();
void RollbackAccountContext();
}

View File

@@ -1,29 +1,30 @@
using Company.Domain._common;
using AccountMangement.Infrastructure.EFCore;
using Company.Domain._common;
using Microsoft.EntityFrameworkCore.Storage;
namespace CompanyManagment.EFCore._common;
public class UnitOfWork : IUnitOfWork
{
private readonly CompanyContext _context;
private readonly AccountContext _context;
private IDbContextTransaction _transaction;
public UnitOfWork(CompanyContext context)
public UnitOfWork(AccountContext context)
{
_context = context;
}
public void Begin()
public void BeginAccountContext()
{
_transaction = _context.Database.BeginTransaction();
}
public void Commit()
public void CommitAccountContext()
{
_transaction?.Commit();
}
public void Rollback()
public void RollbackAccountContext()
{
_transaction?.Rollback();
}

View File

@@ -922,7 +922,117 @@
</div>
</div>
</fieldset>
<!-- مدیریت برنامه نویسان -->
<div class="parent-check">
<label class="btn btn-icon waves-effect btn-default m-b-5 open-close">
<i class="ion-plus"></i> <i class="ion-minus" style="display: none;"></i><input type="checkbox" style="display: none" class="open-btn" />
</label>
<label class="btn btn-inverse waves-effect waves-light m-b-5 parent"> <input type="checkbox" value="99" class="check-btn" data-pm="" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> مدیریت برنامه نویسان </span>&nbsp;</label>
<!-- مدیریت پروژه -->
<div class="child-check level2">
<label class="btn btn-icon waves-effect btn-default m-b-5 open-close">
<i class="ion-plus"></i> <i class="ion-minus" style="display: none;"></i><input type="checkbox" style="display: none" class="open-btn" />
</label>
<label class="btn btn-inverse waves-effect waves-light m-b-5 parentLevel2"> <input type="checkbox" disabled="disabled" value="991" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> مدیریت پروژه </span> </label>
<div class="child-check level3">
<label class="btn btn-icon waves-effect btn-default m-b-5 open-close">
<i class="ion-plus"></i> <i class="ion-minus" style="display: none;"></i><input type="checkbox" style="display: none" class="open-btn" />
</label>
<label class="btn btn-inverse waves-effect waves-light m-b-5 parentLevel2"> <input type="checkbox" disabled="disabled" value="99101" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> ایجاد پروژه </span> </label>
</div>
<!-- ستون لیست پروژه -->
<div class="child-check level3">
<label class="btn btn-icon waves-effect btn-default m-b-5 open-close">
<i class="ion-plus"></i> <i class="ion-minus" style="display: none;"></i><input type="checkbox" style="display: none" class="open-btn" />
</label>
<label class="btn btn-inverse waves-effect waves-light m-b-5 parentLevel2"> <input type="checkbox" disabled="disabled" value="9911" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> ستون لیست پروژه ها </span> </label>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="99111" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> تعیین کاربر </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="99112" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> توضیحات</span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="99113" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> ویرایش</span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="99114" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> حذف</span> </label>
</div>
</div>
<!--ستون بخش اصلی -->
<div class="child-check level3">
<label class="btn btn-icon waves-effect btn-default m-b-5 open-close">
<i class="ion-plus"></i> <i class="ion-minus" style="display: none;"></i><input type="checkbox" style="display: none" class="open-btn" />
</label>
<label class="btn btn-inverse waves-effect waves-light m-b-5 parentLevel2"> <input type="checkbox" disabled="disabled" value="9912" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> ستون بخش اصلی </span> </label>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="99121" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> تعیین کاربر </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="99122" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> توضیحات </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="99124" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> ویرایش </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="99124" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> حذف </span> </label>
</div>
</div>
<!--ستون بخش فرعی -->
<div class="child-check level3">
<label class="btn btn-icon waves-effect btn-default m-b-5 open-close">
<i class="ion-plus"></i> <i class="ion-minus" style="display: none;"></i><input type="checkbox" style="display: none" class="open-btn" />
</label>
<label class="btn btn-inverse waves-effect waves-light m-b-5 parentLevel2"> <input type="checkbox" disabled="disabled" value="9913" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> ستون بخش اصلی </span> </label>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="99131" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> تعیین کاربر </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="99132" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> توضیحات </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="99134" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> ویرایش </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="99134" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> حذف </span> </label>
</div>
</div>
</div>
<!--اجرا-->
<div class="child-check level2">
<label class="btn btn-icon waves-effect btn-default m-b-5 open-close">
<i class="ion-plus"></i> <i class="ion-minus" style="display: none;"></i><input type="checkbox" style="display: none" class="open-btn" />
</label>
<label class="btn btn-inverse waves-effect waves-light m-b-5 parentLevel2"> <input type="checkbox" disabled="disabled" value="992" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> همه </span> </label>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="9921" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> آماده اجرا </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="9922" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> در حال اجرا </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="9023" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> نیمه کاره </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="9024" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> اتمام اجرا </span> </label>
</div>
</div>
</div>
</fieldset>
<div id="hiddenInput" style="display: none">
</div>
@@ -1096,22 +1206,36 @@
</script>
<script>
function saveRole() {
const checks = document.querySelectorAll("input[class='check-btn']");
const checks = document.querySelectorAll("input.check-btn");
for (let i = 0; i < checks.length; i++) {
let pmIndex = 0;
let normalIndex = 0;
if (checks[i].checked) {
$('#hiddenInput').append(
`<input class="item1" type="hidden" value="${checks[i].value}" name="Permissions[${i}]"/>`
);
$("#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" value="${0}" name="Permissions[${i}]"/>`
);
$("#hiddenInput").append(`
<input class="item1" type="hidden"
name="Permissions[${normalIndex}]"
value="${chk.checked ? chk.value : 0}">
`);
normalIndex++;
}
}
});
$('#subm').click();
$("#subm").click();
}
</script>

View File

@@ -1,5 +1,53 @@
@model AccountManagement.Application.Contracts.Account.EditAccount
@{
<style>
/* Toggle Switch */
.switch {
position: relative;
display: inline-block;
width: 46px;
height: 24px;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .3s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 18px;
width: 18px;
left: 3px;
bottom: 3px;
background-color: white;
transition: .3s;
border-radius: 50%;
}
input:checked + .slider {
background-color: #28a745; /* رنگ سبز مشابه Bootstrap */
}
input:checked + .slider:before {
transform: translateX(22px);
}
</style>
}
<div class="modal-header">
@@ -71,7 +119,17 @@
</div>
<div class="row">
<div>
<span>آیا کاربر در پروگرام منیجر هم فعالیت میکند؟</span>
<span>&nbsp;</span>
<label class="switch">
<input id="checkAll" asp-for="IsProgramManagerUser" type="checkbox" />
<span class="slider round"></span>
</label>
</div>
</div>
</div>
</div>

View File

@@ -934,6 +934,112 @@
</div>
<!-- مدیریت برنامه نویسان -->
<div class="parent-check">
<label class="btn btn-icon waves-effect btn-default m-b-5 open-close">
<i class="ion-plus"></i> <i class="ion-minus" style="display: none;"></i><input type="checkbox" style="display: none" class="open-btn" />
</label>
<label class="btn btn-inverse waves-effect waves-light m-b-5 parent"> <input type="checkbox" value="99" class="check-btn" data-pm="" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> مدیریت برنامه نویسان </span>&nbsp;</label>
<!-- مدیریت پروژه -->
<div class="child-check level2">
<label class="btn btn-icon waves-effect btn-default m-b-5 open-close">
<i class="ion-plus"></i> <i class="ion-minus" style="display: none;"></i><input type="checkbox" style="display: none" class="open-btn" />
</label>
<label class="btn btn-inverse waves-effect waves-light m-b-5 parentLevel2"> <input type="checkbox" disabled="disabled" value="991" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> مدیریت پروژه </span> </label>
<div class="child-check level3">
<label class="btn btn-icon waves-effect btn-default m-b-5 open-close">
<i class="ion-plus"></i> <i class="ion-minus" style="display: none;"></i><input type="checkbox" style="display: none" class="open-btn" />
</label>
<label class="btn btn-inverse waves-effect waves-light m-b-5 parentLevel2"> <input type="checkbox" disabled="disabled" value="99101" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> ایجاد پروژه </span> </label>
</div>
<!-- ستون لیست پروژه -->
<div class="child-check level3">
<label class="btn btn-icon waves-effect btn-default m-b-5 open-close">
<i class="ion-plus"></i> <i class="ion-minus" style="display: none;"></i><input type="checkbox" style="display: none" class="open-btn" />
</label>
<label class="btn btn-inverse waves-effect waves-light m-b-5 parentLevel2"> <input type="checkbox" disabled="disabled" value="9911" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> ستون لیست پروژه ها </span> </label>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="99111" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> تعیین کاربر </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="99112" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> توضیحات</span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="99113" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> ویرایش</span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="99114" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> حذف</span> </label>
</div>
</div>
<!--ستون بخش اصلی -->
<div class="child-check level3">
<label class="btn btn-icon waves-effect btn-default m-b-5 open-close">
<i class="ion-plus"></i> <i class="ion-minus" style="display: none;"></i><input type="checkbox" style="display: none" class="open-btn" />
</label>
<label class="btn btn-inverse waves-effect waves-light m-b-5 parentLevel2"> <input type="checkbox" disabled="disabled" value="9912" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> ستون بخش اصلی </span> </label>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="99121" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> تعیین کاربر </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="99122" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> توضیحات </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="99124" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> ویرایش </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="99124" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> حذف </span> </label>
</div>
</div>
<!--ستون بخش فرعی -->
<div class="child-check level3">
<label class="btn btn-icon waves-effect btn-default m-b-5 open-close">
<i class="ion-plus"></i> <i class="ion-minus" style="display: none;"></i><input type="checkbox" style="display: none" class="open-btn" />
</label>
<label class="btn btn-inverse waves-effect waves-light m-b-5 parentLevel2"> <input type="checkbox" disabled="disabled" value="9913" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> ستون بخش اصلی </span> </label>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="99131" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> تعیین کاربر </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="99132" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> توضیحات </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="99134" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> ویرایش </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="99134" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> حذف </span> </label>
</div>
</div>
</div>
<!--اجرا-->
<div class="child-check level2">
<label class="btn btn-icon waves-effect btn-default m-b-5 open-close">
<i class="ion-plus"></i> <i class="ion-minus" style="display: none;"></i><input type="checkbox" style="display: none" class="open-btn" />
</label>
<label class="btn btn-inverse waves-effect waves-light m-b-5 parentLevel2"> <input type="checkbox" disabled="disabled" value="992" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> همه </span> </label>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="9921" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> آماده اجرا </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children "><input type="checkbox" disabled="disabled" value="9922" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> در حال اجرا </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="9023" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> نیمه کاره </span> </label>
</div>
<div class="child-check level3">
<label class="btn btn-inverse waves-effect waves-light m-b-5 children"><input type="checkbox" disabled="disabled" value="9024" class="check-btn" data-pm=""> &nbsp;<span style="bottom: 2px;position: relative"> اتمام اجرا </span> </label>
</div>
</div>
</div>
</fieldset>
<div id="hiddenInput" @*style="display: none"*@>
@@ -1160,22 +1266,35 @@
</script>
<script>
function saveRole() {
const checks = document.querySelectorAll("input[class='check-btn']");
const checks = document.querySelectorAll("input.check-btn");
for (let i = 0; i < checks.length; i++) {
let pmIndex = 0;
let normalIndex = 0;
if (checks[i].checked) {
$('#hiddenInput').append(
`<input class="item1" type="hidden" value="${checks[i].value}" name="Permissions[${i}]"/>`
);
$("#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" value="${0}" name="Permissions[${i}]"/>`
);
$("#hiddenInput").append(`
<input class="item1" type="hidden"
name="Permissions[${normalIndex}]"
value="${chk.checked ? chk.value : 0}">
`);
normalIndex++;
}
}
});
$('#subm').click();
$("#subm").click();
}
</script>

View File

@@ -1,12 +1,16 @@
using _0_Framework.Application;
using _0_Framework.Application.Sms;
using AccountManagement.Application.Contracts.Account;
using AccountManagement.Application.Contracts.ProgramManagerApiResult;
using AccountManagement.Application.Contracts.Role;
using AccountManagement.Domain.AccountAgg;
using AccountManagement.Domain.InternalApiCaller;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.SignalR;
using Newtonsoft.Json;
using ServiceHost.Hubs;
namespace ServiceHost.Areas.Admin.Pages.Accounts.Account;
@@ -81,8 +85,42 @@ public class IndexModel : PageModel
public IActionResult OnGetEdit(long id)
{
{
var account = _accountApplication.GetDetails(id);
var key = SecretKeys.ProgramManagerInternalApi;
var apiResult = InternalApiCaller.GetAsync<SingleUserResponseResult>(
$"api/user/{account.Id}",
key
);
// حالا نتیجه دیسریال شده در apiResult.Result قرار دارد
var result = apiResult.Result;
// مثل قبل:
if (result != null && result.isSuccess)
{
account.IsProgramManagerUser = (result.Data.accountId == account.Id);
}
else
{
account.IsProgramManagerUser = false;
}
account.Roles = _roleApplication.List();
return Partial("Edit", account);
}
@@ -100,7 +138,31 @@ public class IndexModel : PageModel
var rol = new List<int>();
foreach (var item in role.MappedPermissions) rol.Add(item.Code);
role.Permissions = rol;
var key = SecretKeys.ProgramManagerInternalApi;
var apiResult = InternalApiCaller.GetAsync<RoleResponse>(
"api/role",
key,
new Dictionary<string, object>
{
{ "RoleName", "" },
{ "GozareshgirRoleId", role.Id }
}
);
role.Permissions = rol;
if (apiResult.Success)
{
if (apiResult.Result.isSuccess && apiResult.Result.data.role.Any())
{
var pmPermission = apiResult.Result.data.role.FirstOrDefault()!.permissions;
role.Permissions.AddRange(pmPermission);
}
}
return Partial("EditRole", role);
}

View File

@@ -45,51 +45,3 @@ namespace ServiceHost.Pages
}
}
}
public record SingleUserRespnsResult
{
public bool isSuccess { get; set; }
public Data Data { get; set; }
}
public record Data
{
public long id { get; set; }
/// <summary>
/// نام و نام خانوادگی
/// </summary>
public string fullName { get; set; }
/// <summary>
/// نام کاربری
/// </summary>
public string userName { get; set; }
/// <summary>
/// مسیر عکس پروفایل
/// </summary>
public string profilePhotoPath { get; set; }
/// <summary>
/// شماره موبایل
/// </summary>
public string mobile { get; set; }
/// <summary>
/// فعال/غیر فعال بودن یوزر
/// </summary>
public bool isActive { get; set; }
/// <summary>
/// گذرواژه
/// </summary>
public string password { get; set; }
/// <summary>
/// ای دی اکانت کاربر در گزارشگیر
/// </summary>
public long? accountId { get; set; }
}

View File

@@ -36,6 +36,7 @@ using MongoDB.Driver;
using Parbad.Builder;
using Parbad.Gateway.Sepehr;
using Swashbuckle.AspNetCore.SwaggerUI;
using AccountManagement.Domain.InternalApiCaller;
var builder = WebApplication.CreateBuilder(args);
@@ -333,7 +334,13 @@ builder.Services.AddParbad().ConfigureGateways(gateways =>
var app = builder.Build();
app.UseCors("AllowSpecificOrigins");
#region InternalProgarmManagerApi
var baseUrl = builder.Configuration["InternalProgramManagerApi:BaseUrl"];
InternalApiCaller.SetBaseUrl(baseUrl);
#endregion
#region Mahan

View File

@@ -41,11 +41,16 @@
},
"SmsSettings": {
"IsTestMode": true,
"TestNumbers": [ "09116967898"
//, "09116067106", "09114221321"
"TestNumbers": [
"09116967898"
//, "09116067106", "09114221321"
]
},
"InternalProgramManagerApi": {
"BaseUrl": "https://localhost:7032"
},
"SepehrGateWayTerminalId": 99213700
}

View File

@@ -36,6 +36,10 @@
"IsTestMode": false,
"TestNumbers": []
},
"InternalProgramManagerApi": {
"BaseUrl": "https://localhost:7032"
},
"SepehrGateWayTerminalId": 99213700
}