diff --git a/AccountManagement.Application.Contracts/Account/IAccountApplication.cs b/AccountManagement.Application.Contracts/Account/IAccountApplication.cs
index ac21411b..badb8c23 100644
--- a/AccountManagement.Application.Contracts/Account/IAccountApplication.cs
+++ b/AccountManagement.Application.Contracts/Account/IAccountApplication.cs
@@ -2,15 +2,21 @@
using System.Collections.Generic;
using System.Threading.Tasks;
+using AccountManagement.Application.Contracts.ProgramManager;
namespace AccountManagement.Application.Contracts.Account;
public interface IAccountApplication
{
AccountViewModel GetAccountBy(long id);
- OperationResult Create(CreateAccount command);
+ ///
+ /// ایجاد کاربر گزارشگیر و پروگرام منیجر
+ ///
+ ///
+ ///
+ Task Create(CreateAccount command);
OperationResult RegisterClient(RegisterAccount command);
- OperationResult Edit(EditAccount command);
+ Task Edit(EditAccount command);
OperationResult EditClient(EditClientAccount command);
OperationResult ChangePassword(ChangePassword command);
OperationResult Login(Login command);
@@ -67,6 +73,13 @@ public interface IAccountApplication
List GetAdminAccountsNew();
void CameraLogin(CameraLoginRequest request);
+
+ ///
+ /// دریافت کاربر پروگرام منیجر با اکانت آی دی
+ ///
+ ///
+ ///
+ Task GetPmUserByAccountId(long accountId);
}
public class CameraLoginRequest
diff --git a/AccountManagement.Application.Contracts/ProgramManager/GetPmUserDto.cs b/AccountManagement.Application.Contracts/ProgramManager/GetPmUserDto.cs
new file mode 100644
index 00000000..d5901f72
--- /dev/null
+++ b/AccountManagement.Application.Contracts/ProgramManager/GetPmUserDto.cs
@@ -0,0 +1,56 @@
+using System.Collections.Generic;
+
+namespace AccountManagement.Application.Contracts.ProgramManager;
+
+public class GetPmUserDto
+{
+ ///
+ /// نام و نام خانوادگی
+ ///
+ public string FullName { get; set; }
+
+ ///
+ /// نام کاربری
+ ///
+ public string UserName { get; set; }
+
+
+
+ ///
+ /// مسیر عکس پروفایل
+ ///
+ public string ProfilePhotoPath { get; set; }
+
+ ///
+ /// شماره موبایل
+ ///
+ public string Mobile { get; set; }
+
+
+ ///
+ /// فعال/غیر فعال بودن یوزر
+ ///
+ public bool IsActive { get; set; }
+
+ ///
+ /// آی دی کاربر در گزارشگیر
+ ///
+ public long? AccountId { get; set; }
+
+ ///
+ /// نقش ها
+ ///
+ public List Roles { get; set; }
+
+
+ public List RoleListDto { get; set; }
+
+
+}
+public record RoleListDto
+{
+ public string RoleName { get; set; }
+ public long RoleId { get; set; }
+ public List Permissions { get; set; }
+
+}
diff --git a/AccountManagement.Application.Contracts/ProgramManager/GetRoleDto.cs b/AccountManagement.Application.Contracts/ProgramManager/GetRoleDto.cs
new file mode 100644
index 00000000..a3256abd
--- /dev/null
+++ b/AccountManagement.Application.Contracts/ProgramManager/GetRoleDto.cs
@@ -0,0 +1,28 @@
+using System.Collections.Generic;
+
+namespace AccountManagement.Application.Contracts.ProgramManager;
+
+public record GetPmRolesDto
+{
+ ///
+ /// آی دی نقش
+ ///
+ public long Id { get; set; }
+
+ ///
+ /// نام نقش
+ ///
+ public string RoleName { get; set; }
+
+ ///
+ /// آی دی نقش در گزارشگیر
+ ///
+ public long? GozareshgirRoleId { get; set; }
+
+ ///
+ /// لیست کدهای دسترسی
+ ///
+ public List Permissions { get; set; }
+
+
+}
\ No newline at end of file
diff --git a/AccountManagement.Application.Contracts/Role/IRoleApplication.cs b/AccountManagement.Application.Contracts/Role/IRoleApplication.cs
index bfe6e358..9d49f8e2 100644
--- a/AccountManagement.Application.Contracts/Role/IRoleApplication.cs
+++ b/AccountManagement.Application.Contracts/Role/IRoleApplication.cs
@@ -1,13 +1,25 @@
using _0_Framework.Application;
+using AccountManagement.Application.Contracts.ProgramManager;
+using Microsoft.AspNetCore.Mvc.Rendering;
using System.Collections.Generic;
+using System.Threading.Tasks;
namespace AccountManagement.Application.Contracts.Role
{
public interface IRoleApplication
{
- OperationResult Create(CreateRole command);
- OperationResult Edit(EditRole command);
+ Task Create(CreateRole command);
+ Task Edit(EditRole command);
List List();
EditRole GetDetails(long id);
+
+ #region ProgramManager
+
+ Task GetPmRoleList(long? gozareshgirRoleId);
+ Task> GetPmRoleListToEdit(long? gozareshgirRoleId);
+
+
+ #endregion
+
}
}
diff --git a/AccountManagement.Application/AccountApplication.cs b/AccountManagement.Application/AccountApplication.cs
index 42185fe5..bba09128 100644
--- a/AccountManagement.Application/AccountApplication.cs
+++ b/AccountManagement.Application/AccountApplication.cs
@@ -1,36 +1,40 @@
-using System;
-using System.Collections;
-using _0_Framework.Application;
+using _0_Framework.Application;
+using _0_Framework.Application.Sms;
+using _0_Framework.Exceptions;
using AccountManagement.Application.Contracts.Account;
+using AccountManagement.Application.Contracts.ProgramManagerApiResult;
using AccountManagement.Domain.AccountAgg;
+using AccountManagement.Domain.AccountLeftWorkAgg;
+using AccountManagement.Domain.CameraAccountAgg;
+using AccountManagement.Domain.InternalApiCaller;
+using AccountManagement.Domain.PmDomains.PmRoleUserAgg;
+using AccountManagement.Domain.PmDomains.PmUserAgg;
+using AccountManagement.Domain.PositionAgg;
+using AccountManagement.Domain.RoleAgg;
+using AccountManagement.Domain.SubAccountAgg;
+using AccountManagement.Domain.SubAccountPermissionSubtitle1Agg;
+using AccountManagement.Domain.SubAccountRoleAgg;
+using Company.Domain._common;
+using Company.Domain.WorkshopAgg;
+using Company.Domain.WorkshopSubAccountAgg;
+using CompanyManagment.App.Contracts.Workshop;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.JsonPatch.Operations;
+using Microsoft.AspNetCore.Mvc.Rendering;
+using Microsoft.EntityFrameworkCore;
+using Newtonsoft.Json;
+using System;
+using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Runtime.InteropServices;
-using System.Threading;
-using System.Threading.Tasks;
-using _0_Framework.Application.Sms;
-using AccountManagement.Domain.AccountLeftWorkAgg;
-using AccountManagement.Domain.CameraAccountAgg;
-using AccountManagement.Domain.RoleAgg;
-using CompanyManagment.App.Contracts.Workshop;
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc.Rendering;
-using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
-using Company.Domain.WorkshopAgg;
using System.Security.Claims;
using System.Text;
-using _0_Framework.Exceptions;
-using AccountManagement.Domain.PositionAgg;
-using AccountManagement.Domain.SubAccountAgg;
-using AccountManagement.Domain.SubAccountPermissionSubtitle1Agg;
-using AccountManagement.Domain.SubAccountRoleAgg;
-using Company.Domain.WorkshopSubAccountAgg;
-using Newtonsoft.Json;
-using Microsoft.EntityFrameworkCore;
-using Company.Domain._common;
-using AccountManagement.Domain.InternalApiCaller;
-using AccountManagement.Application.Contracts.ProgramManagerApiResult;
+using System.Threading;
+using System.Threading.Tasks;
+using AccountManagement.Application.Contracts.ProgramManager;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
//using AccountManagement.Domain.RoleAgg;
@@ -52,10 +56,11 @@ public class AccountApplication : IAccountApplication
private readonly ISubAccountRoleRepository _subAccountRoleRepository;
private readonly IWorkshopSubAccountRepository _workshopSubAccountRepository;
private readonly ISubAccountPermissionSubtitle1Repository _accountPermissionSubtitle1Repository;
+ private readonly IPmUserRepository _pmUserRepository;
private readonly IUnitOfWork _unitOfWork;
public AccountApplication(IAccountRepository accountRepository, IPasswordHasher passwordHasher,
- IFileUploader fileUploader, IAuthHelper authHelper, IRoleRepository roleRepository, IWorker worker, ISmsService smsService, ICameraAccountRepository cameraAccountRepository, IPositionRepository positionRepository, IAccountLeftworkRepository accountLeftworkRepository, IWorkshopRepository workshopRepository, ISubAccountRepository subAccountRepository, ISubAccountRoleRepository subAccountRoleRepository, IWorkshopSubAccountRepository workshopSubAccountRepository, ISubAccountPermissionSubtitle1Repository accountPermissionSubtitle1Repository, IUnitOfWork unitOfWork)
+ IFileUploader fileUploader, IAuthHelper authHelper, IRoleRepository roleRepository, IWorker worker, ISmsService smsService, ICameraAccountRepository cameraAccountRepository, IPositionRepository positionRepository, IAccountLeftworkRepository accountLeftworkRepository, IWorkshopRepository workshopRepository, ISubAccountRepository subAccountRepository, ISubAccountRoleRepository subAccountRoleRepository, IWorkshopSubAccountRepository workshopSubAccountRepository, ISubAccountPermissionSubtitle1Repository accountPermissionSubtitle1Repository, IUnitOfWork unitOfWork, IPmUserRepository pmUserRepository)
{
_authHelper = authHelper;
_roleRepository = roleRepository;
@@ -69,6 +74,7 @@ public class AccountApplication : IAccountApplication
_workshopSubAccountRepository = workshopSubAccountRepository;
_accountPermissionSubtitle1Repository = accountPermissionSubtitle1Repository;
_unitOfWork = unitOfWork;
+ _pmUserRepository = pmUserRepository;
_fileUploader = fileUploader;
_passwordHasher = passwordHasher;
_accountRepository = accountRepository;
@@ -132,7 +138,7 @@ public class AccountApplication : IAccountApplication
};
}
- public OperationResult Create(CreateAccount command)
+ public async Task Create(CreateAccount command)
{
var operation = new OperationResult();
@@ -159,36 +165,61 @@ public class AccountApplication : IAccountApplication
if (command.IsProgramManagerUser)
{
- var parameters = new CreateProgramManagerUser(
- command.Fullname,
- command.Username,
- password,
- command.Mobile,
- command.Email,
- account.id,
- command.UserRoles
- );
- var url = "api/user/create";
- var key = SecretKeys.ProgramManagerInternalApi;
-
- var response = InternalApiCaller.PostAsync(
- url,
- key,
- parameters
- );
-
- if (!response.Success)
+ try
{
- _unitOfWork.RollbackAccountContext();
- return operation.Failed(response.Error);
+ 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 => !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("خطا در ایجاد کاربر پروگرام منیجر");
}
- if (!response.Result.isSuccess)
- {
- _unitOfWork.RollbackAccountContext();
- return operation.Failed(response.Result.errorMessage);
- }
+ //var url = "api/user/create";
+ //var key = SecretKeys.ProgramManagerInternalApi;
+
+ //var response = InternalApiCaller.PostAsync(
+ // 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);
+ //}
}
_unitOfWork.CommitAccountContext();
@@ -230,7 +261,7 @@ public class AccountApplication : IAccountApplication
return opreation.Succcedded(register.id, message: "ثبت نام شما با موفقیت انجام شد");
}
- public OperationResult Edit(EditAccount command)
+ public async Task Edit(EditAccount command)
{
var operation = new OperationResult();
var account = _accountRepository.Get(command.Id);
@@ -249,47 +280,62 @@ public class AccountApplication : IAccountApplication
_accountRepository.SaveChanges();
var key = SecretKeys.ProgramManagerInternalApi;
- var apiResult = InternalApiCaller.GetAsync(
- $"api/user/{account.id}",
- key
- );
+ //var apiResult = InternalApiCaller.GetAsync(
+ // $"api/user/{account.id}",
+ // key
+ //);
+ var userResult = _pmUserRepository.GetByPmUsertoEditbyAccountId(account.id).GetAwaiter().GetResult();
-
//اگر کاربر در پروگرام منیجر قبلا ایجاد شده
- if (apiResult.Success && apiResult.Result.Data.accountId == account.id)
+ if (userResult != null)
{
if (!command.UserRoles.Any())
+ {
+ _unitOfWork.RollbackAccountContext();
return operation.Failed("حداقل یک نقش باید انتخاب شود");
+ }
+
+ try
+ {
- 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)
+ 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(response.Error);
-
+ 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.Result.isSuccess)
- {
- _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);
+ //}
}
else //اگر کاربر قبلا ایجاد نشده
@@ -298,38 +344,77 @@ public class AccountApplication : IAccountApplication
if (command.IsProgramManagerUser)
{
if (!command.UserRoles.Any())
+ {
+ _unitOfWork.RollbackAccountContext();
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(
- url,
- key,
- parameters
- );
-
- if (!response.Success)
- {
- _unitOfWork.RollbackAccountContext();
- return operation.Failed(response.Error);
-
}
- if (!response.Result.isSuccess)
+ if (_pmUserRepository.Exists(x => x.FullName == command.Fullname))
{
_unitOfWork.RollbackAccountContext();
- return operation.Failed(response.Error);
+ 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("این شماره همراه قبلا به فرد دیگری اختصاص داده شده است");
+ }
+
+
+ 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("خطا در ویرایش کاربر پروگرام منیجر");
+ }
+
+
+ //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(
+ // url,
+ // key,
+ // parameters
+ //);
+
+ //if (!response.Success)
+ //{
+ // _unitOfWork.RollbackAccountContext();
+ // return operation.Failed(response.Error);
+
+ //}
+
+ //if (!response.Result.isSuccess)
+ //{
+ // _unitOfWork.RollbackAccountContext();
+ // return operation.Failed(response.Error);
+ //}
}
}
@@ -968,4 +1053,9 @@ public class AccountApplication : IAccountApplication
_authHelper.CameraSignIn(authViewModel);
}
+
+ public async Task GetPmUserByAccountId(long accountId)
+ {
+ return await _pmUserRepository.GetPmUserByAccountId(accountId);
+ }
}
\ No newline at end of file
diff --git a/AccountManagement.Application/RoleApplication.cs b/AccountManagement.Application/RoleApplication.cs
index 51d05489..6ea605d4 100644
--- a/AccountManagement.Application/RoleApplication.cs
+++ b/AccountManagement.Application/RoleApplication.cs
@@ -3,25 +3,36 @@ using AccountManagement.Application.Contracts.Role;
using AccountManagement.Domain.RoleAgg;
using System.Collections.Generic;
using System.Linq;
+using System.Threading.Tasks;
+using AccountManagement.Application.Contracts.ProgramManager;
using AccountManagement.Application.Contracts.ProgramManagerApiResult;
using AccountManagement.Domain.InternalApiCaller;
using Company.Domain._common;
using AccountManagement.Application.Contracts.Ticket;
+using AccountManagement.Domain.PmDomains.PmPermissionAgg;
+using AccountManagement.Domain.PmDomains.PmRoleAgg;
+using AccountManagement.Domain.PmDomains.PmUserAgg;
+using Microsoft.AspNetCore.Mvc.Rendering;
+using Role = AccountManagement.Domain.RoleAgg.Role;
namespace AccountManagement.Application;
public class RoleApplication : IRoleApplication
{
private readonly IRoleRepository _roleRepository;
+ private readonly IPmRoleRepository _pmRoleRepository;
+ private readonly IPmUserRepository _pmUserRepository;
private readonly IUnitOfWork _unitOfWork;
- public RoleApplication(IRoleRepository roleRepository, IUnitOfWork unitOfWork)
+ public RoleApplication(IRoleRepository roleRepository, IUnitOfWork unitOfWork, IPmRoleRepository pmRoleRepository, IPmUserRepository pmUserRepository)
{
_roleRepository = roleRepository;
_unitOfWork = unitOfWork;
+ _pmRoleRepository = pmRoleRepository;
+ _pmUserRepository = pmUserRepository;
}
- public OperationResult Create(CreateRole command)
+ public async Task Create(CreateRole command)
{
var operation = new OperationResult();
if (_roleRepository.Exists(x => x.Name == command.Name))
@@ -36,35 +47,49 @@ public class RoleApplication : IRoleApplication
var pmPermissions = command.PmPermissions.Where(x => x > 0).ToList();
if (pmPermissions.Any())
{
- var parameters = new CreateProgramManagerRole
+ try
{
- RoleName = command.Name,
- Permissions = pmPermissions,
- GozareshgirRoleId = role.id
+ var pmPermissionsData = pmPermissions.Where(x => x > 0).Select(x => new PmPermission(x)).ToList();
+ var pmRole = new PmRole(command.Name, role.id, pmPermissionsData);
+ await _pmRoleRepository.CreateAsync(pmRole);
+ await _pmRoleRepository.SaveChangesAsync();
- };
-
- var url = "api/role";
- var key = SecretKeys.ProgramManagerInternalApi;
-
- var response = InternalApiCaller.PostAsync(
- url,
- key,
- parameters
- );
-
-
- if (!response.Success)
+ }
+ catch (System.Exception)
{
_unitOfWork.RollbackAccountContext();
- return operation.Failed("ارتباط با اپلیکیش پروگرام منیجر برقرار نشد");
+ return operation.Failed("خطا در ویرایش دسترسی ها در پروگرام منیجر");
}
- if (!response.Result.isSuccess)
- {
- _unitOfWork.RollbackAccountContext();
- return operation.Failed(response.Result.errorMessage);
- }
+ //var parameters = new CreateProgramManagerRole
+ //{
+ // RoleName = command.Name,
+ // Permissions = pmPermissions,
+ // GozareshgirRoleId = role.id
+
+ //};
+
+ //var url = "api/role";
+ //var key = SecretKeys.ProgramManagerInternalApi;
+
+ //var response = InternalApiCaller.PostAsync(
+ // url,
+ // key,
+ // parameters
+ //);
+
+
+ //if (!response.Success)
+ //{
+ // _unitOfWork.RollbackAccountContext();
+ // return operation.Failed("ارتباط با اپلیکیش پروگرام منیجر برقرار نشد");
+ //}
+
+ //if (!response.Result.isSuccess)
+ //{
+ // _unitOfWork.RollbackAccountContext();
+ // return operation.Failed(response.Result.errorMessage);
+ //}
}
@@ -74,7 +99,7 @@ public class RoleApplication : IRoleApplication
return operation.Succcedded();
}
- public OperationResult Edit(EditRole command)
+ public async Task Edit(EditRole command)
{
var operation = new OperationResult();
var role = _roleRepository.Get(command.Id);
@@ -89,7 +114,7 @@ public class RoleApplication : IRoleApplication
var permissions = command.Permissions.Where(x => x > 0).Select(x => new Permission(x)).ToList();
-
+
_unitOfWork.BeginAccountContext();
role.Edit(command.Name, permissions);
@@ -99,117 +124,120 @@ public class RoleApplication : IRoleApplication
//یافتن نقش در پروگرام منیجر
- var apiResult = InternalApiCaller.GetAsync(
- "api/role",
- key,
- new Dictionary
- {
- { "RoleName", "" },
+ //var apiResult = InternalApiCaller.GetAsync(
+ // "api/role",
+ // key,
+ // new Dictionary
+ // {
+ // { "RoleName", "" },
- { "GozareshgirRoleId", command.Id}
- }
- );
+ // { "GozareshgirRoleId", command.Id}
+ // }
+ //);
+ var pmRoleResult = await _pmRoleRepository.GetPmRoleToEdit(command.Id);
- if (apiResult.Success)
+
+ //اگر این نقش در پروگرام منیجر وجود داشت ویرایش کن
+ if (pmRoleResult != null)
{
-
- if (apiResult.Result.isSuccess)
+
+ try
{
- //اگر این نقش در پروگرام منیجر وجود داشت ویرایش کن
- if (apiResult.Result.data.role.Any())
- {
- var parameters = new CreateProgramManagerRole
- {
- RoleName = command.Name,
- Permissions = pmPermissions,
- GozareshgirRoleId = role.id
-
- };
-
- var url = "api/role/edit";
-
-
- var response = InternalApiCaller.PostAsync(
- url,
- key,
- parameters
- );
-
-
- if (!response.Success)
- {
- _unitOfWork.RollbackAccountContext();
- return operation.Failed("ارتباط با اپلیکیش پروگرام منیجر برقرار نشد");
- }
-
- if (!response.Result.isSuccess)
- {
- _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(
- url,
- key,
- parameters
- );
-
-
- if (!response.Success)
- {
- _unitOfWork.RollbackAccountContext();
- return operation.Failed("ارتباط با اپلیکیش پروگرام منیجر برقرار نشد");
- }
-
- if (!response.Result.isSuccess)
- {
- _unitOfWork.RollbackAccountContext();
- return operation.Failed(response.Result.errorMessage);
- }
- }
- }
-
+ var pmpermissionsData = pmPermissions.Where(x => x > 0).Select(x => new PmPermission(x)).ToList();
+ pmRoleResult.Edit(command.Name, pmpermissionsData);
+ await _pmRoleRepository.SaveChangesAsync();
}
- else
+ catch (System.Exception)
{
_unitOfWork.RollbackAccountContext();
- return operation.Failed("ارتباط با اپلیکیش پروگرام منیجر برقرار نشد");
-
+ return operation.Failed("خطا در ویرایش دسترسی ها در پروگرام منیجر");
}
+
+ //var parameters = new CreateProgramManagerRole
+ //{
+ // RoleName = command.Name,
+ // Permissions = pmPermissions,
+ // GozareshgirRoleId = role.id
+
+ //};
+ //var url = "api/role/edit";
+ //var response = InternalApiCaller.PostAsync(
+ // url,
+ // key,
+ // parameters
+ //);
+
+
+ //if (!response.Success)
+ //{
+ // _unitOfWork.RollbackAccountContext();
+ // return operation.Failed("ارتباط با اپلیکیش پروگرام منیجر برقرار نشد");
+ //}
+
+ //if (!response.Result.isSuccess)
+ //{
+ // _unitOfWork.RollbackAccountContext();
+ // return operation.Failed(response.Result.errorMessage);
+ //}
}
- else
+ else //اگر نقش در پروگرام منیجر وجود نداشت
{
- _unitOfWork.RollbackAccountContext();
- return operation.Failed("ارتباط با اپلیکیش پروگرام منیجر برقرار نشد");
+
+ //اگر تیک پرمیشن های پروگرام منیجر زده شده
+ //این نقش را سمت پروگرام منیجر بساز
+ if (pmPermissions.Any())
+ {
+
+
+ try
+ {
+ var pmPermissionsData = pmPermissions.Where(x => x > 0).Select(x => new PmPermission(x)).ToList();
+ var pmRole = new PmRole(command.Name, command.Id, pmPermissionsData);
+ await _pmRoleRepository.CreateAsync(pmRole);
+ await _pmRoleRepository.SaveChangesAsync();
+
+ }
+ catch (System.Exception)
+ {
+ _unitOfWork.RollbackAccountContext();
+ return operation.Failed("خطا در ویرایش دسترسی ها در پروگرام منیجر");
+ }
+
+ //var parameters = new CreateProgramManagerRole
+ //{
+ // RoleName = command.Name,
+ // Permissions = pmPermissions,
+ // GozareshgirRoleId = role.id
+
+ //};
+
+ //var url = "api/role";
+
+
+ //var response = InternalApiCaller.PostAsync(
+ // url,
+ // key,
+ // parameters
+ //);
+
+
+ //if (!response.Success)
+ //{
+ // _unitOfWork.RollbackAccountContext();
+ // return operation.Failed("ارتباط با اپلیکیش پروگرام منیجر برقرار نشد");
+ //}
+
+ //if (!response.Result.isSuccess)
+ //{
+ // _unitOfWork.RollbackAccountContext();
+ // return operation.Failed(response.Result.errorMessage);
+ //}
+ }
}
-
-
-
-
-
-
-
+ _unitOfWork.CommitAccountContext();
return operation.Succcedded();
}
@@ -222,4 +250,23 @@ public class RoleApplication : IRoleApplication
{
return _roleRepository.List();
}
+
+
+ public async Task GetPmRoleList(long? gozareshgirRoleId)
+ {
+ var rolse = await _pmRoleRepository.GetPmRoleList(gozareshgirRoleId);
+ return new SelectList(rolse, "Id", "RoleName");
+
+
+ }
+
+ public async Task> GetPmRoleListToEdit(long? gozareshgirRoleId)
+ {
+ return await _pmRoleRepository.GetPmRoleList(gozareshgirRoleId);
+
+ }
+
+
+
+
}
\ No newline at end of file
diff --git a/AccountManagement.Configuration/PmDbBootstrapper.cs b/AccountManagement.Configuration/PmDbBootstrapper.cs
new file mode 100644
index 00000000..84d93fa8
--- /dev/null
+++ b/AccountManagement.Configuration/PmDbBootstrapper.cs
@@ -0,0 +1,18 @@
+using AccountManagement.Domain.PmDomains.PmRoleAgg;
+using AccountManagement.Domain.PmDomains.PmUserAgg;
+using AccountMangement.Infrastructure.EFCore.PmDbConetxt;
+using AccountMangement.Infrastructure.EFCore.Repository.PmRepositories;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace AccountManagement.Configuration;
+
+public class PmDbBootstrapper
+{
+ public static void Configure(IServiceCollection services, string connectionString)
+ {
+ services.AddTransient();
+ services.AddTransient();
+ services.AddDbContext(x => x.UseSqlServer(connectionString));
+ }
+}
\ No newline at end of file
diff --git a/AccountManagement.Domain/PmDomains/PmPermissionAgg/Permission.cs b/AccountManagement.Domain/PmDomains/PmPermissionAgg/PmPermission.cs
similarity index 77%
rename from AccountManagement.Domain/PmDomains/PmPermissionAgg/Permission.cs
rename to AccountManagement.Domain/PmDomains/PmPermissionAgg/PmPermission.cs
index 7be4d5d0..691a9954 100644
--- a/AccountManagement.Domain/PmDomains/PmPermissionAgg/Permission.cs
+++ b/AccountManagement.Domain/PmDomains/PmPermissionAgg/PmPermission.cs
@@ -7,13 +7,13 @@ using AccountManagement.Domain.PmDomains.PmRoleAgg;
namespace AccountManagement.Domain.PmDomains.PmPermissionAgg;
-public class Permission
+public class PmPermission
{
public long Id { get; private set; }
public int Code { get; private set; }
- public Role Role { get; private set; }
+ public PmRole Role { get; private set; }
- public Permission(int code)
+ public PmPermission(int code)
{
Code = code;
}
diff --git a/AccountManagement.Domain/PmDomains/PmRoleAgg/IPmRoleRepository.cs b/AccountManagement.Domain/PmDomains/PmRoleAgg/IPmRoleRepository.cs
new file mode 100644
index 00000000..49cb7f4e
--- /dev/null
+++ b/AccountManagement.Domain/PmDomains/PmRoleAgg/IPmRoleRepository.cs
@@ -0,0 +1,15 @@
+using _0_Framework.Domain;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using AccountManagement.Application.Contracts.ProgramManager;
+
+namespace AccountManagement.Domain.PmDomains.PmRoleAgg;
+
+public interface IPmRoleRepository :IRepository
+{
+ Task> GetPmRoleList(long? gozareshgirRoleId);
+
+ Task GetPmRoleToEdit(long gozareshgirRoleId);
+
+}
+
diff --git a/AccountManagement.Domain/PmDomains/PmRoleAgg/Role.cs b/AccountManagement.Domain/PmDomains/PmRoleAgg/PmRole.cs
similarity index 65%
rename from AccountManagement.Domain/PmDomains/PmRoleAgg/Role.cs
rename to AccountManagement.Domain/PmDomains/PmRoleAgg/PmRole.cs
index 698d271b..ddb305ea 100644
--- a/AccountManagement.Domain/PmDomains/PmRoleAgg/Role.cs
+++ b/AccountManagement.Domain/PmDomains/PmRoleAgg/PmRole.cs
@@ -4,7 +4,7 @@ using AccountManagement.Domain.PmDomains.PmPermissionAgg;
namespace AccountManagement.Domain.PmDomains.PmRoleAgg;
-public class Role : EntityBase
+public class PmRole : EntityBase
{
///
/// نام نقش
@@ -15,7 +15,7 @@ public class Role : EntityBase
///
/// لیست پرمیشن کد ها
///
- public List Permissions { get; private set; }
+ public List PmPermission { get; private set; }
///
/// ای دی نقش در گزارشگیر
@@ -23,23 +23,23 @@ public class Role : EntityBase
public long? GozareshgirRoleId { get; private set; }
- protected Role()
+ protected PmRole()
{
}
- public Role(string roleName,long? gozareshgirRolId, List permissions)
+ public PmRole(string roleName,long? gozareshgirRolId, List permissions)
{
RoleName = roleName;
- Permissions = permissions;
+ PmPermission = permissions;
GozareshgirRoleId = gozareshgirRolId;
}
- public void Edit(string roleName, List permissions)
+ public void Edit(string roleName, List permissions)
{
RoleName = roleName;
- Permissions = permissions;
+ PmPermission = permissions;
}
diff --git a/AccountManagement.Domain/PmDomains/PmRoleUserAgg/RoleUser.cs b/AccountManagement.Domain/PmDomains/PmRoleUserAgg/PmRoleUser.cs
similarity index 72%
rename from AccountManagement.Domain/PmDomains/PmRoleUserAgg/RoleUser.cs
rename to AccountManagement.Domain/PmDomains/PmRoleUserAgg/PmRoleUser.cs
index 335ee877..a7cf6355 100644
--- a/AccountManagement.Domain/PmDomains/PmRoleUserAgg/RoleUser.cs
+++ b/AccountManagement.Domain/PmDomains/PmRoleUserAgg/PmRoleUser.cs
@@ -2,9 +2,9 @@
namespace AccountManagement.Domain.PmDomains.PmRoleUserAgg;
-public class RoleUser
+public class PmRoleUser
{
- public RoleUser(long roleId)
+ public PmRoleUser(long roleId)
{
RoleId = roleId;
}
@@ -13,7 +13,7 @@ public class RoleUser
public long RoleId { get; private set; }
- public User User { get; set; }
+ public PmUser User { get; set; }
}
\ No newline at end of file
diff --git a/AccountManagement.Domain/PmDomains/PmUserAgg/IPmUserRepository.cs b/AccountManagement.Domain/PmDomains/PmUserAgg/IPmUserRepository.cs
new file mode 100644
index 00000000..c28c3db1
--- /dev/null
+++ b/AccountManagement.Domain/PmDomains/PmUserAgg/IPmUserRepository.cs
@@ -0,0 +1,21 @@
+using _0_Framework.Domain;
+using AccountManagement.Application.Contracts.ProgramManager;
+using System.Threading.Tasks;
+
+namespace AccountManagement.Domain.PmDomains.PmUserAgg;
+
+public interface IPmUserRepository : IRepository
+{
+ ///
+ /// دریافت کاربر پروگرام منیجر جهتد ویرایش
+ ///
+ ///
+ ///
+ Task GetByPmUsertoEditbyAccountId(long accountId);
+ ///
+ /// دریافت کرابر پروگرام منیجر با اکانت آی دی در گزارشگیر
+ ///
+ ///
+ ///
+ Task GetPmUserByAccountId(long accountId);
+}
\ No newline at end of file
diff --git a/AccountManagement.Domain/PmDomains/PmUserAgg/User.cs b/AccountManagement.Domain/PmDomains/PmUserAgg/PmUser.cs
similarity index 90%
rename from AccountManagement.Domain/PmDomains/PmUserAgg/User.cs
rename to AccountManagement.Domain/PmDomains/PmUserAgg/PmUser.cs
index 876d2bb4..6b0c531a 100644
--- a/AccountManagement.Domain/PmDomains/PmUserAgg/User.cs
+++ b/AccountManagement.Domain/PmDomains/PmUserAgg/PmUser.cs
@@ -9,7 +9,7 @@ namespace AccountManagement.Domain.PmDomains.PmUserAgg;
///
/// کاربر
///
-public class User : EntityBase
+public class PmUser : EntityBase
{
///
/// ایجاد
@@ -21,7 +21,7 @@ public class User : EntityBase
///
///
///
- public User(string fullName, string userName, string password, string mobile, string email, long? accountId, List roles)
+ public PmUser(string fullName, string userName, string password, string mobile, string email, long? accountId, List roles)
{
FullName = fullName;
UserName = userName;
@@ -33,7 +33,7 @@ public class User : EntityBase
RoleUser = roles;
}
- protected User()
+ protected PmUser()
{
}
@@ -87,7 +87,7 @@ public class User : EntityBase
///
/// لیست پرمیشن کد ها
///
- public List RoleUser { get; private set; }
+ public List RoleUser { get; private set; }
///
@@ -98,7 +98,7 @@ public class User : EntityBase
///
///
///
- public void Edit(string fullName, string userName, string mobile, List roles, bool isActive)
+ public void Edit(string fullName, string userName, string mobile, List roles, bool isActive)
{
FullName = fullName;
UserName = userName;
diff --git a/AccountMangement.Infrastructure.EFCore/Mappings/PmMappings/PmRoleMapping.cs b/AccountMangement.Infrastructure.EFCore/Mappings/PmMappings/PmRoleMapping.cs
new file mode 100644
index 00000000..00324b3d
--- /dev/null
+++ b/AccountMangement.Infrastructure.EFCore/Mappings/PmMappings/PmRoleMapping.cs
@@ -0,0 +1,24 @@
+using AccountManagement.Domain.PmDomains.PmRoleAgg;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Metadata.Builders;
+
+namespace AccountMangement.Infrastructure.EFCore.Mappings.PmMappings;
+
+public class PmRoleMapping : IEntityTypeConfiguration
+{
+ public void Configure(EntityTypeBuilder builder)
+ {
+ builder.ToTable("PmRoles", t => t.ExcludeFromMigrations());
+ builder.HasKey(x => x.id);
+
+ builder.Property(x => x.RoleName).HasMaxLength(100).IsRequired();
+
+ builder.OwnsMany(x => x.PmPermission, navigationBuilder =>
+ {
+ navigationBuilder.HasKey(x => x.Id);
+ navigationBuilder.ToTable("PmRolePermissions", t => t.ExcludeFromMigrations());
+
+ navigationBuilder.WithOwner(x => x.Role);
+ });
+ }
+}
\ No newline at end of file
diff --git a/CompanyManagment.EFCore/Mapping/PmMappings/UserMapping.cs b/AccountMangement.Infrastructure.EFCore/Mappings/PmMappings/PmUserMapping.cs
similarity index 66%
rename from CompanyManagment.EFCore/Mapping/PmMappings/UserMapping.cs
rename to AccountMangement.Infrastructure.EFCore/Mappings/PmMappings/PmUserMapping.cs
index 39ca99ac..9ee5e126 100644
--- a/CompanyManagment.EFCore/Mapping/PmMappings/UserMapping.cs
+++ b/AccountMangement.Infrastructure.EFCore/Mappings/PmMappings/PmUserMapping.cs
@@ -1,15 +1,15 @@
-using GozareshgirProgramManager.Domain.UserAgg.Entities;
+using AccountManagement.Domain.PmDomains.PmUserAgg;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
-namespace GozareshgirProgramManager.Infrastructure.Persistence.Mappings;
+namespace AccountMangement.Infrastructure.EFCore.Mappings.PmMappings;
-public class UserMapping :IEntityTypeConfiguration
+public class PmUserMapping :IEntityTypeConfiguration
{
- public void Configure(EntityTypeBuilder builder)
+ public void Configure(EntityTypeBuilder builder)
{
builder.ToTable("Users");
- builder.HasKey(x => x.Id);
+ builder.HasKey(x => x.id);
builder.Property(x => x.FullName).HasMaxLength(100).IsRequired();
builder.Property(x => x.UserName).HasMaxLength(100).IsRequired();
@@ -24,11 +24,7 @@ public class UserMapping :IEntityTypeConfiguration
navigationBuilder.ToTable("RoleUsers");
navigationBuilder.WithOwner(x => x.User);
});
-
- builder.HasMany(x=>x.RefreshTokens)
- .WithOne(x=>x.User)
- .HasForeignKey(x=>x.UserId)
- .OnDelete(DeleteBehavior.Cascade);
+
}
}
\ No newline at end of file
diff --git a/AccountMangement.Infrastructure.EFCore/PmDbConetxt/PmDbContext.cs b/AccountMangement.Infrastructure.EFCore/PmDbConetxt/PmDbContext.cs
new file mode 100644
index 00000000..a668490e
--- /dev/null
+++ b/AccountMangement.Infrastructure.EFCore/PmDbConetxt/PmDbContext.cs
@@ -0,0 +1,32 @@
+using AccountManagement.Domain.PmDomains.PmRoleAgg;
+using AccountManagement.Domain.PmDomains.PmUserAgg;
+using AccountMangement.Infrastructure.EFCore.Mappings;
+using AccountMangement.Infrastructure.EFCore.Mappings.PmMappings;
+using Microsoft.EntityFrameworkCore;
+
+namespace AccountMangement.Infrastructure.EFCore.PmDbConetxt;
+
+public class PmDbContext : DbContext
+{
+ public PmDbContext(DbContextOptions options) : base(options)
+ {
+
+ }
+ public DbSet Users { get; set; } = null!;
+ public DbSet PmRoles { get; set; } = null!;
+
+
+ public PmDbContext()
+ {
+
+ }
+
+
+ protected override void OnModelCreating(ModelBuilder modelBuilder)
+ {
+ var assembly = typeof(PmUserMapping).Assembly;
+ modelBuilder.ApplyConfigurationsFromAssembly(assembly);
+ //SubAccountPermissionSeeder.Seed(modelBuilder);
+ base.OnModelCreating(modelBuilder);
+ }
+}
\ No newline at end of file
diff --git a/AccountMangement.Infrastructure.EFCore/Repository/PmRepositories/PmRoleRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/PmRepositories/PmRoleRepository.cs
new file mode 100644
index 00000000..e3f93e53
--- /dev/null
+++ b/AccountMangement.Infrastructure.EFCore/Repository/PmRepositories/PmRoleRepository.cs
@@ -0,0 +1,49 @@
+using _0_Framework.InfraStructure;
+using AccountManagement.Application.Contracts.ProgramManager;
+using AccountManagement.Domain.PmDomains.PmRoleAgg;
+using AccountMangement.Infrastructure.EFCore.PmDbConetxt;
+using Microsoft.EntityFrameworkCore;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
+
+namespace AccountMangement.Infrastructure.EFCore.Repository.PmRepositories;
+
+public class PmRoleRepository : RepositoryBase, IPmRoleRepository
+{
+ private readonly PmDbContext _pmDbContext;
+ public PmRoleRepository(PmDbContext context) : base(context)
+ {
+ _pmDbContext = context;
+ }
+
+ public async Task> GetPmRoleList(long? gozareshgirRoleId)
+ {
+ var query = _pmDbContext.PmRoles.AsQueryable();
+ if (gozareshgirRoleId != null && gozareshgirRoleId > 0)
+ query = query.Where(x => x.GozareshgirRoleId == gozareshgirRoleId);
+ var res = await query
+ .Select(p => new GetPmRolesDto()
+ {
+ Id = p.id,
+ RoleName = p.RoleName,
+ GozareshgirRoleId = p.GozareshgirRoleId,
+ Permissions = p.PmPermission.Select(x => x.Code).ToList()
+
+ })
+ .ToListAsync();
+
+ return res;
+ }
+
+
+
+ public async Task GetPmRoleToEdit(long gozareshgirRoleId)
+ {
+ return await _pmDbContext.PmRoles.FirstOrDefaultAsync(x => x.GozareshgirRoleId == gozareshgirRoleId);
+
+ }
+
+}
\ No newline at end of file
diff --git a/AccountMangement.Infrastructure.EFCore/Repository/PmRepositories/PmUserRepository.cs b/AccountMangement.Infrastructure.EFCore/Repository/PmRepositories/PmUserRepository.cs
new file mode 100644
index 00000000..70a378df
--- /dev/null
+++ b/AccountMangement.Infrastructure.EFCore/Repository/PmRepositories/PmUserRepository.cs
@@ -0,0 +1,47 @@
+using _0_Framework.InfraStructure;
+using AccountManagement.Application.Contracts.ProgramManager;
+using AccountManagement.Domain.PmDomains.PmUserAgg;
+using AccountMangement.Infrastructure.EFCore.PmDbConetxt;
+using Microsoft.EntityFrameworkCore;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace AccountMangement.Infrastructure.EFCore.Repository.PmRepositories;
+
+public class PmUserRepository :RepositoryBase, IPmUserRepository
+{
+ private readonly PmDbContext _pmDbContext;
+ public PmUserRepository(PmDbContext context, PmDbContext pmDbContext) : base(context)
+ {
+ _pmDbContext = pmDbContext;
+ }
+ public async Task GetByPmUsertoEditbyAccountId(long accountId)
+ {
+ return await _pmDbContext.Users.FirstOrDefaultAsync(x => x.AccountId == accountId);
+ }
+
+ public async Task GetPmUserByAccountId(long accountId)
+ {
+ var query = await _pmDbContext.Users.FirstOrDefaultAsync(x => x.AccountId == accountId);
+ if (query == null)
+ return new GetPmUserDto();
+ List roles = query.RoleUser.Select(x => x.RoleId).ToList();
+ return new GetPmUserDto()
+ {
+ FullName = query.FullName,
+ UserName = query.UserName,
+ ProfilePhotoPath = query.ProfilePhotoPath,
+ Mobile = query.Mobile,
+ IsActive = query.IsActive,
+ AccountId = query.AccountId,
+ Roles = roles,
+ RoleListDto = await _pmDbContext.PmRoles.Where(x => roles.Contains(x.id)).Select(x => new RoleListDto()
+ {
+ RoleName = x.RoleName,
+ RoleId = x.id,
+ Permissions = x.PmPermission.Select(x => x.Code).ToList()
+ }).ToListAsync(),
+ };
+ }
+}
\ No newline at end of file
diff --git a/CompanyManagment.EFCore/Mapping/PmMappings/RoleMapping.cs b/CompanyManagment.EFCore/Mapping/PmMappings/RoleMapping.cs
deleted file mode 100644
index 8d6292d6..00000000
--- a/CompanyManagment.EFCore/Mapping/PmMappings/RoleMapping.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using AccountManagement.Domain.PmDomains.PmRoleAgg;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.EntityFrameworkCore.Metadata.Builders;
-
-namespace CompanyManagment.EFCore.Mapping.PmMappings;
-
-public class RoleMapping : IEntityTypeConfiguration
-{
- public void Configure(EntityTypeBuilder builder)
- {
- builder.ToTable("Roles");
- builder.HasKey(x => x.id);
-
- builder.Property(x => x.RoleName).HasMaxLength(100).IsRequired();
-
- builder.OwnsMany(x => x.Permissions, navigationBuilder =>
- {
- navigationBuilder.HasKey(x => x.Id);
- navigationBuilder.ToTable("RolePermissions");
- navigationBuilder.WithOwner(x => x.Role);
- });
- }
-}
\ No newline at end of file
diff --git a/CompanyManagment.EFCore/PmDbContext.cs b/CompanyManagment.EFCore/PmDbContext.cs
deleted file mode 100644
index e2890873..00000000
--- a/CompanyManagment.EFCore/PmDbContext.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-
-using Microsoft.EntityFrameworkCore;
-using System;
-using AccountManagement.Domain.PmDomains.PmRoleAgg;
-using AccountManagement.Domain.PmDomains.PmUserAgg;
-
-namespace CompanyManagment.EFCore;
-
-public class PmDbContext : DbContext
-{
- public PmDbContext(DbContextOptions options) : base(options)
- {
-
- }
- public DbSet Users { get; set; } = null!;
- public DbSet Roles { get; set; } = null!;
-
-
- public PmDbContext()
- {
-
- }
-
-
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- modelBuilder.ApplyConfigurationsFromAssembly(typeof(PmDbContext).Assembly);
- base.OnModelCreating(modelBuilder);
- }
-}
\ No newline at end of file
diff --git a/PersonalContractingParty.Config/PmDbBootstrapper.cs b/PersonalContractingParty.Config/PmDbBootstrapper.cs
deleted file mode 100644
index 8d0b130d..00000000
--- a/PersonalContractingParty.Config/PmDbBootstrapper.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Company.Domain.InsuranceJobItemAgg;
-using Company.Domain.InsurancJobAgg;
-using CompanyManagment.App.Contracts.InsuranceJob;
-using CompanyManagment.Application;
-using CompanyManagment.EFCore;
-using CompanyManagment.EFCore.Repository;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace PersonalContractingParty.Config;
-
-public class PmDbBootstrapper
-{
- public static void Configure(IServiceCollection services, string connectionString)
- {
-
- services.AddDbContext(x => x.UseSqlServer(connectionString));
- }
-}
\ No newline at end of file
diff --git a/ServiceHost/Areas/Admin/Pages/Accounts/Account/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Accounts/Account/Index.cshtml.cs
index 6f2d7132..e4597d4f 100644
--- a/ServiceHost/Areas/Admin/Pages/Accounts/Account/Index.cshtml.cs
+++ b/ServiceHost/Areas/Admin/Pages/Accounts/Account/Index.cshtml.cs
@@ -55,41 +55,42 @@ public class IndexModel : PageModel
public IActionResult OnGetCreate()
- {
+ {
-
+ var pmRolseSelectList = _roleApplication.GetPmRoleList(null).GetAwaiter().GetResult();
var command = new CreateAccount
{
- Roles = _roleApplication.List()
- };
- var key = SecretKeys.ProgramManagerInternalApi;
- var response = InternalApiCaller.GetAsync(
- "api/role",
- key,
- new Dictionary
- {
- { "RoleName", "" },
+ Roles = _roleApplication.List(),
+ RoleList = pmRolseSelectList,
+ };
+ //var key = SecretKeys.ProgramManagerInternalApi;
+ //var response = InternalApiCaller.GetAsync(
+ // "api/role",
+ // key,
+ // new Dictionary
+ // {
+ // { "RoleName", "" },
- { "GozareshgirRoleId", "" }
- }
- );
+ // { "GozareshgirRoleId", "" }
+ // }
+ //);
- if (response.Success)
- {
- if (response.Result.isSuccess)
- {
- command.RoleList = new SelectList(response.Result.data.role, "id", "roleName");
+ //if (response.Success)
+ //{
+ // if (response.Result.isSuccess)
+ // {
+ // command.RoleList = new SelectList(response.Result.data.role, "id", "roleName");
- }
+ // }
- }
+ //}
return Partial("./Create", command);
}
public IActionResult OnPostCreate(CreateAccount command)
{
- var result = _accountApplication.Create(command);
+ var result = _accountApplication.Create(command).GetAwaiter().GetResult();
return new JsonResult(result);
}
@@ -102,7 +103,7 @@ public class IndexModel : PageModel
public IActionResult OnPostCreateRole(CreateRole command)
{
- var result = _roleApplication.Create(command);
+ var result = _roleApplication.Create(command).GetAwaiter().GetResult();
return new JsonResult(result);
}
@@ -112,55 +113,51 @@ public class IndexModel : PageModel
var account = _accountApplication.GetDetails(id);
+ //var key = SecretKeys.ProgramManagerInternalApi;
+
+ //var apiResult = InternalApiCaller.GetAsync(
+ // $"api/user/{account.Id}",
+ // key
+ //);
+ var result = _accountApplication.GetPmUserByAccountId(account.Id).GetAwaiter().GetResult();
- var key = SecretKeys.ProgramManagerInternalApi;
-
- var apiResult = InternalApiCaller.GetAsync(
- $"api/user/{account.Id}",
- key
- );
-
-
-
- // حالا نتیجه دیسریال شده در apiResult.Result قرار دارد
- var result = apiResult.Result;
-
// مثل قبل:
- if (result != null && result.isSuccess)
+ if (result != null)
{
- account.IsProgramManagerUser = (result.Data.accountId == account.Id && result.Data.isActive);
- account.UserRoles = apiResult.Result.Data.Roles;
+ 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 response = InternalApiCaller.GetAsync(
+ // "api/role",
+ // key,
+ // new Dictionary
+ // {
+ // { "RoleName", "" },
- var response = InternalApiCaller.GetAsync(
- "api/role",
- key,
- new Dictionary
- {
- { "RoleName", "" },
+ // { "GozareshgirRoleId", "" }
+ // }
+ //);
- { "GozareshgirRoleId", "" }
- }
- );
+ //if (response.Success)
+ //{
+ // if (response.Result.isSuccess)
+ // {
+ // account.RoleList = new SelectList(response.Result.data.role, "id", "roleName");
- if (response.Success)
- {
- if (response.Result.isSuccess)
- {
- account.RoleList = new SelectList(response.Result.data.role, "id", "roleName");
-
- }
+ // }
- }
+ //}
@@ -172,7 +169,7 @@ public class IndexModel : PageModel
public JsonResult OnPostEdit(EditAccount command)
{
- var result = _accountApplication.Edit(command);
+ var result = _accountApplication.Edit(command).GetAwaiter().GetResult();
return new JsonResult(result);
}
@@ -182,26 +179,27 @@ public class IndexModel : PageModel
var rol = new List();
foreach (var item in role.MappedPermissions) rol.Add(item.Code);
- var key = SecretKeys.ProgramManagerInternalApi;
+ //var key = SecretKeys.ProgramManagerInternalApi;
- var apiResult = InternalApiCaller.GetAsync(
- "api/role",
- key,
- new Dictionary
- {
- { "RoleName", "" },
+ //var apiResult = InternalApiCaller.GetAsync(
+ // "api/role",
+ // key,
+ // new Dictionary
+ // {
+ // { "RoleName", "" },
- { "GozareshgirRoleId", role.Id }
- }
- );
+ // { "GozareshgirRoleId", role.Id }
+ // }
+ //);
+ var pmRoleResult = _roleApplication.GetPmRoleListToEdit(role.Id).GetAwaiter().GetResult();
role.Permissions = rol;
- if (apiResult.Success)
+ if (pmRoleResult != null)
{
- if (apiResult.Result.isSuccess && apiResult.Result.data.role.Any())
+ if (pmRoleResult.Any())
{
- var pmPermission = apiResult.Result.data.role.FirstOrDefault()!.permissions;
+ var pmPermission = pmRoleResult.FirstOrDefault()!.Permissions;
role.Permissions.AddRange(pmPermission);
}
@@ -213,7 +211,7 @@ public class IndexModel : PageModel
public JsonResult OnPostEditRole(EditRole command)
{
- var result = _roleApplication.Edit(command);
+ var result = _roleApplication.Edit(command).GetAwaiter().GetResult();
return new JsonResult(result);
}