edit role completed
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user