create PmRole Completed
This commit is contained in:
@@ -155,7 +155,7 @@ public class AccountApplication : IAccountApplication
|
||||
|
||||
}
|
||||
var account = new Account(command.Fullname, command.Username, password, command.Mobile, command.RoleId,
|
||||
picturePath, roleName.Name, "true", "false", command.IsProgramManagerUser);
|
||||
picturePath, roleName.Name, "true", "false");
|
||||
|
||||
_unitOfWork.BeginAccountContext();
|
||||
|
||||
@@ -163,64 +163,64 @@ public class AccountApplication : IAccountApplication
|
||||
_accountRepository.Create(account);
|
||||
_accountRepository.SaveChanges();
|
||||
|
||||
//if (command.IsProgramManagerUser)
|
||||
//{
|
||||
if (command.IsProgramManagerUser)
|
||||
{
|
||||
|
||||
// try
|
||||
// {
|
||||
// if (_pmUserRepository.Exists(x => x.FullName == command.Fullname))
|
||||
// {
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed("نام و خانوادگی تکراری است");
|
||||
// }
|
||||
try
|
||||
{
|
||||
if (_pmUserRepository.Exists(x => x.FullName == command.Fullname))
|
||||
{
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("نام و خانوادگی تکراری است");
|
||||
}
|
||||
|
||||
// if (_pmUserRepository.Exists(x => x.UserName == command.Username))
|
||||
// {
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed("نام کاربری تکراری است");
|
||||
// }
|
||||
if (_pmUserRepository.Exists(x => x.UserName == command.Username))
|
||||
{
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("نام کاربری تکراری است");
|
||||
}
|
||||
|
||||
// if (_pmUserRepository.Exists(x => !string.IsNullOrWhiteSpace(x.Mobile) && x.Mobile == command.Mobile))
|
||||
// {
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed("این شماره همراه قبلا به فرد دیگری اختصاص داده شده است");
|
||||
// }
|
||||
if (_pmUserRepository.Exists(x => !string.IsNullOrWhiteSpace(x.Mobile) && x.Mobile == command.Mobile))
|
||||
{
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("این شماره همراه قبلا به فرد دیگری اختصاص داده شده است");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// var userRoles = command.UserRoles.Where(x => x > 0).Select(x => new PmRoleUser(x)).ToList();
|
||||
// var create = new PmUser(command.Fullname, command.Username, command.Password, command.Mobile,
|
||||
// null, account.id, userRoles);
|
||||
// await _pmUserRepository.CreateAsync(create);
|
||||
// await _pmUserRepository.SaveChangesAsync();
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed("خطا در ایجاد کاربر پروگرام منیجر");
|
||||
// }
|
||||
var userRoles = command.UserRoles.Where(x => x > 0).Select(x => new PmRoleUser(x)).ToList();
|
||||
var create = new PmUser(command.Fullname, command.Username, command.Password, command.Mobile,
|
||||
null, account.id, userRoles);
|
||||
await _pmUserRepository.CreateAsync(create);
|
||||
await _pmUserRepository.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("خطا در ایجاد کاربر پروگرام منیجر");
|
||||
}
|
||||
|
||||
// //var url = "api/user/create";
|
||||
// //var key = SecretKeys.ProgramManagerInternalApi;
|
||||
//var url = "api/user/create";
|
||||
//var key = SecretKeys.ProgramManagerInternalApi;
|
||||
|
||||
// //var response = InternalApiCaller.PostAsync<CreateProgramManagerUser, ApiResponse>(
|
||||
// // url,
|
||||
// // key,
|
||||
// // parameters
|
||||
// //);
|
||||
//var response = InternalApiCaller.PostAsync<CreateProgramManagerUser, ApiResponse>(
|
||||
// url,
|
||||
// key,
|
||||
// parameters
|
||||
//);
|
||||
|
||||
// //if (!response.Success)
|
||||
// //{
|
||||
// // _unitOfWork.RollbackAccountContext();
|
||||
// // return operation.Failed(response.Error);
|
||||
// //}
|
||||
//if (!response.Success)
|
||||
//{
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed(response.Error);
|
||||
//}
|
||||
|
||||
// //if (!response.Result.isSuccess)
|
||||
// //{
|
||||
// // _unitOfWork.RollbackAccountContext();
|
||||
// // return operation.Failed(response.Result.errorMessage);
|
||||
// //}
|
||||
//}
|
||||
//if (!response.Result.isSuccess)
|
||||
//{
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed(response.Result.errorMessage);
|
||||
//}
|
||||
}
|
||||
|
||||
_unitOfWork.CommitAccountContext();
|
||||
return operation.Succcedded();
|
||||
@@ -276,148 +276,148 @@ public class AccountApplication : IAccountApplication
|
||||
var path = $"profilePhotos";
|
||||
var picturePath = _fileUploader.Upload(command.ProfilePhoto, path);
|
||||
_unitOfWork.BeginAccountContext();
|
||||
account.Edit(command.Fullname, command.Username, command.Mobile, command.RoleId, picturePath, roleName.Name, command.IsProgramManagerUser);
|
||||
account.Edit(command.Fullname, command.Username, command.Mobile, command.RoleId, picturePath, roleName.Name);
|
||||
_accountRepository.SaveChanges();
|
||||
// var key = SecretKeys.ProgramManagerInternalApi;
|
||||
var key = SecretKeys.ProgramManagerInternalApi;
|
||||
|
||||
//var apiResult = InternalApiCaller.GetAsync<SingleUserResponseResult>(
|
||||
// $"api/user/{account.id}",
|
||||
// key
|
||||
//);
|
||||
// var userResult = _pmUserRepository.GetByPmUsertoEditbyAccountId(account.id).GetAwaiter().GetResult();
|
||||
var userResult = _pmUserRepository.GetByPmUsertoEditbyAccountId(account.id).GetAwaiter().GetResult();
|
||||
|
||||
|
||||
|
||||
//اگر کاربر در پروگرام منیجر قبلا ایجاد شده
|
||||
//if (userResult != null)
|
||||
//{
|
||||
// if (!command.UserRoles.Any())
|
||||
// {
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed("حداقل یک نقش باید انتخاب شود");
|
||||
// }
|
||||
if (userResult != null)
|
||||
{
|
||||
if (!command.UserRoles.Any())
|
||||
{
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("حداقل یک نقش باید انتخاب شود");
|
||||
}
|
||||
|
||||
// try
|
||||
// {
|
||||
try
|
||||
{
|
||||
|
||||
// var userRoles = command.UserRoles.Where(x => x > 0).Select(x => new PmRoleUser(x)).ToList();
|
||||
// userResult.Edit(command.Fullname, command.Username, command.Mobile, userRoles, command.IsProgramManagerUser);
|
||||
// await _pmUserRepository.SaveChangesAsync();
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed("خطا در ویرایش کاربر پروگرام منیجر");
|
||||
// }
|
||||
// //var parameters = new EditUserCommand(
|
||||
// // command.Fullname,
|
||||
// // command.Username,
|
||||
// // command.Mobile,
|
||||
// // account.id,
|
||||
// // command.UserRoles,
|
||||
// // command.IsProgramManagerUser
|
||||
// //);
|
||||
// //var url = "api/user/edit";
|
||||
// //var response = InternalApiCaller.PostAsync<EditUserCommand, ApiResponse>(
|
||||
// // url,
|
||||
// // key,
|
||||
// // parameters
|
||||
// //);
|
||||
var userRoles = command.UserRoles.Where(x => x > 0).Select(x => new PmRoleUser(x)).ToList();
|
||||
userResult.Edit(command.Fullname, command.Username, command.Mobile, userRoles, command.IsProgramManagerUser);
|
||||
await _pmUserRepository.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("خطا در ویرایش کاربر پروگرام منیجر");
|
||||
}
|
||||
//var parameters = new EditUserCommand(
|
||||
// command.Fullname,
|
||||
// command.Username,
|
||||
// command.Mobile,
|
||||
// account.id,
|
||||
// command.UserRoles,
|
||||
// command.IsProgramManagerUser
|
||||
//);
|
||||
//var url = "api/user/edit";
|
||||
//var response = InternalApiCaller.PostAsync<EditUserCommand, ApiResponse>(
|
||||
// url,
|
||||
// key,
|
||||
// parameters
|
||||
//);
|
||||
|
||||
// //if (!response.Success)
|
||||
// //{
|
||||
// // _unitOfWork.RollbackAccountContext();
|
||||
// // return operation.Failed(response.Error);
|
||||
//if (!response.Success)
|
||||
//{
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed(response.Error);
|
||||
|
||||
// //}
|
||||
//}
|
||||
|
||||
// //if (!response.Result.isSuccess)
|
||||
// //{
|
||||
// // _unitOfWork.RollbackAccountContext();
|
||||
// // return operation.Failed(response.Error);
|
||||
// //}
|
||||
//if (!response.Result.isSuccess)
|
||||
//{
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed(response.Error);
|
||||
//}
|
||||
|
||||
//}
|
||||
//else //اگر کاربر قبلا ایجاد نشده
|
||||
//{
|
||||
// //اگر تیک فعالیت در پروگرام منیجر روشن بود
|
||||
// if (command.IsProgramManagerUser)
|
||||
// {
|
||||
// if (!command.UserRoles.Any())
|
||||
// {
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed("حداقل یک نقش باید انتخاب شود");
|
||||
// }
|
||||
}
|
||||
else //اگر کاربر قبلا ایجاد نشده
|
||||
{
|
||||
//اگر تیک فعالیت در پروگرام منیجر روشن بود
|
||||
if (command.IsProgramManagerUser)
|
||||
{
|
||||
if (!command.UserRoles.Any())
|
||||
{
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("حداقل یک نقش باید انتخاب شود");
|
||||
}
|
||||
|
||||
// if (_pmUserRepository.Exists(x => x.FullName == command.Fullname))
|
||||
// {
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed("نام و خانوادگی تکراری است");
|
||||
// }
|
||||
if (_pmUserRepository.Exists(x => x.FullName == command.Fullname))
|
||||
{
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("نام و خانوادگی تکراری است");
|
||||
}
|
||||
|
||||
// if (_pmUserRepository.Exists(x => x.UserName == command.Username))
|
||||
// {
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed("نام کاربری تکراری است");
|
||||
// }
|
||||
if (_pmUserRepository.Exists(x => x.UserName == command.Username))
|
||||
{
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("نام کاربری تکراری است");
|
||||
}
|
||||
|
||||
// if (_pmUserRepository.Exists(x => !string.IsNullOrWhiteSpace(x.Mobile) && x.Mobile == command.Mobile))
|
||||
// {
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed("این شماره همراه قبلا به فرد دیگری اختصاص داده شده است");
|
||||
// }
|
||||
if (_pmUserRepository.Exists(x => !string.IsNullOrWhiteSpace(x.Mobile) && x.Mobile == command.Mobile))
|
||||
{
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("این شماره همراه قبلا به فرد دیگری اختصاص داده شده است");
|
||||
}
|
||||
|
||||
|
||||
// try
|
||||
// {
|
||||
// var userRoles = command.UserRoles.Where(x => x > 0).Select(x => new PmRoleUser(x)).ToList();
|
||||
// var create = new PmUser(command.Fullname, command.Username, account.Password, command.Mobile,
|
||||
// null, account.id, userRoles);
|
||||
// await _pmUserRepository.CreateAsync(create);
|
||||
// await _pmUserRepository.SaveChangesAsync();
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
try
|
||||
{
|
||||
var userRoles = command.UserRoles.Where(x => x > 0).Select(x => new PmRoleUser(x)).ToList();
|
||||
var create = new PmUser(command.Fullname, command.Username, account.Password, command.Mobile,
|
||||
null, account.id, userRoles);
|
||||
await _pmUserRepository.CreateAsync(create);
|
||||
await _pmUserRepository.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed("خطا در ویرایش کاربر پروگرام منیجر");
|
||||
// }
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("خطا در ویرایش کاربر پروگرام منیجر");
|
||||
}
|
||||
|
||||
|
||||
// //var parameters = new CreateProgramManagerUser(
|
||||
// // command.Fullname,
|
||||
// // command.Username,
|
||||
// // account.Password,
|
||||
// // command.Mobile,
|
||||
// // command.Email,
|
||||
// // account.id,
|
||||
// // command.UserRoles
|
||||
// //);
|
||||
//var parameters = new CreateProgramManagerUser(
|
||||
// command.Fullname,
|
||||
// command.Username,
|
||||
// account.Password,
|
||||
// command.Mobile,
|
||||
// command.Email,
|
||||
// account.id,
|
||||
// command.UserRoles
|
||||
//);
|
||||
|
||||
// //var url = "api/user/Create";
|
||||
//var url = "api/user/Create";
|
||||
|
||||
|
||||
// //var response = InternalApiCaller.PostAsync<CreateProgramManagerUser, ApiResponse>(
|
||||
// // url,
|
||||
// // key,
|
||||
// // parameters
|
||||
// //);
|
||||
//var response = InternalApiCaller.PostAsync<CreateProgramManagerUser, ApiResponse>(
|
||||
// url,
|
||||
// key,
|
||||
// parameters
|
||||
//);
|
||||
|
||||
// //if (!response.Success)
|
||||
// //{
|
||||
// // _unitOfWork.RollbackAccountContext();
|
||||
// // return operation.Failed(response.Error);
|
||||
//if (!response.Success)
|
||||
//{
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed(response.Error);
|
||||
|
||||
// //}
|
||||
//}
|
||||
|
||||
// //if (!response.Result.isSuccess)
|
||||
// //{
|
||||
// // _unitOfWork.RollbackAccountContext();
|
||||
// // return operation.Failed(response.Error);
|
||||
// //}
|
||||
// }
|
||||
//if (!response.Result.isSuccess)
|
||||
//{
|
||||
// _unitOfWork.RollbackAccountContext();
|
||||
// return operation.Failed(response.Error);
|
||||
//}
|
||||
}
|
||||
|
||||
//}
|
||||
}
|
||||
|
||||
_unitOfWork.CommitAccountContext();
|
||||
return operation.Succcedded();
|
||||
@@ -919,7 +919,7 @@ public class AccountApplication : IAccountApplication
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(command.PhoneNumber))
|
||||
{
|
||||
entity.Edit(entity.Fullname, entity.Username, command.PhoneNumber, entity.RoleId, entity.ProfilePhoto, entity.RoleName, false);
|
||||
entity.Edit(entity.Fullname, entity.Username, command.PhoneNumber, entity.RoleId, entity.ProfilePhoto, entity.RoleName);
|
||||
}
|
||||
_accountRepository.SaveChanges();
|
||||
return op.Succcedded();
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<ProjectReference Include="..\AccountManagement.Application.Contracts\AccountManagement.Application.Contracts.csproj" />
|
||||
<ProjectReference Include="..\AccountManagement.Domain\AccountManagement.Domain.csproj" />
|
||||
<ProjectReference Include="..\Company.Domain\Company.Domain.csproj" />
|
||||
<ProjectReference Include="..\Shared.Contracts\Shared.Contracts.csproj" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ 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;
|
||||
@@ -13,7 +12,10 @@ using AccountManagement.Domain.PmDomains.PmPermissionAgg;
|
||||
using AccountManagement.Domain.PmDomains.PmRoleAgg;
|
||||
using AccountManagement.Domain.PmDomains.PmUserAgg;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Shared.Contracts.PmRole.Commands;
|
||||
using GetPmRolesDto = Shared.Contracts.PmRole.Queries.GetPmRolesDto;
|
||||
using Role = AccountManagement.Domain.RoleAgg.Role;
|
||||
using Shared.Contracts.PmRole.Queries;
|
||||
|
||||
namespace AccountManagement.Application;
|
||||
|
||||
@@ -22,14 +24,18 @@ public class RoleApplication : IRoleApplication
|
||||
private readonly IRoleRepository _roleRepository;
|
||||
private readonly IPmRoleRepository _pmRoleRepository;
|
||||
private readonly IPmUserRepository _pmUserRepository;
|
||||
private readonly IPmRoleQueryService _pmRoleQueryService;
|
||||
private readonly IPmRoleCommandService _pmRoleCommandService;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public RoleApplication(IRoleRepository roleRepository, IUnitOfWork unitOfWork, IPmRoleRepository pmRoleRepository, IPmUserRepository pmUserRepository)
|
||||
public RoleApplication(IRoleRepository roleRepository, IUnitOfWork unitOfWork, IPmRoleRepository pmRoleRepository, IPmUserRepository pmUserRepository, IPmRoleQueryService pmRoleQueryService, IPmRoleCommandService pmRoleCommandService)
|
||||
{
|
||||
_roleRepository = roleRepository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_pmRoleRepository = pmRoleRepository;
|
||||
_pmUserRepository = pmUserRepository;
|
||||
_pmRoleQueryService = pmRoleQueryService;
|
||||
_pmRoleCommandService = pmRoleCommandService;
|
||||
}
|
||||
|
||||
public async Task<OperationResult> Create(CreateRole command)
|
||||
@@ -47,19 +53,15 @@ public class RoleApplication : IRoleApplication
|
||||
var pmPermissions = command.PmPermissions.Where(x => x > 0).ToList();
|
||||
if (pmPermissions.Any())
|
||||
{
|
||||
try
|
||||
{
|
||||
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();
|
||||
|
||||
}
|
||||
catch (System.Exception)
|
||||
|
||||
var pmRole = new CreatePmRoleDto{ RoleName = command.Name, Permissions = pmPermissions, GozareshgirRoleId = role.id};
|
||||
var res =await _pmRoleCommandService.Create(pmRole);
|
||||
if (!res.Item1)
|
||||
{
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("خطا در ویرایش دسترسی ها در پروگرام منیجر");
|
||||
}
|
||||
|
||||
|
||||
//var parameters = new CreateProgramManagerRole
|
||||
//{
|
||||
@@ -136,8 +138,8 @@ public class RoleApplication : IRoleApplication
|
||||
//);
|
||||
|
||||
|
||||
var pmRoleResult = await _pmRoleRepository.GetPmRoleToEdit(command.Id);
|
||||
|
||||
var pmRoleListResult = await _pmRoleQueryService.GetPmRoleList(command.Id);
|
||||
var pmRoleResult = pmRoleListResult.FirstOrDefault();
|
||||
|
||||
//اگر این نقش در پروگرام منیجر وجود داشت ویرایش کن
|
||||
if (pmRoleResult != null)
|
||||
@@ -146,8 +148,8 @@ public class RoleApplication : IRoleApplication
|
||||
try
|
||||
{
|
||||
var pmpermissionsData = pmPermissions.Where(x => x > 0).Select(x => new PmPermission(x)).ToList();
|
||||
pmRoleResult.Edit(command.Name, pmpermissionsData);
|
||||
await _pmRoleRepository.SaveChangesAsync();
|
||||
//pmRoleResult.Edit(command.Name, pmpermissionsData);
|
||||
// await _pmRoleRepository.SaveChangesAsync();
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
@@ -254,7 +256,7 @@ public class RoleApplication : IRoleApplication
|
||||
|
||||
public async Task<SelectList> GetPmRoleList(long? gozareshgirRoleId)
|
||||
{
|
||||
var rolse = await _pmRoleRepository.GetPmRoleList(gozareshgirRoleId);
|
||||
var rolse = await _pmRoleQueryService.GetPmRoleList(gozareshgirRoleId);
|
||||
return new SelectList(rolse, "Id", "RoleName");
|
||||
|
||||
|
||||
@@ -262,7 +264,7 @@ public class RoleApplication : IRoleApplication
|
||||
|
||||
public async Task<List<GetPmRolesDto>> GetPmRoleListToEdit(long? gozareshgirRoleId)
|
||||
{
|
||||
return await _pmRoleRepository.GetPmRoleList(gozareshgirRoleId);
|
||||
return await _pmRoleQueryService.GetPmRoleList(gozareshgirRoleId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user