Update pmUser and create completed
This commit is contained in:
@@ -34,8 +34,9 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AccountManagement.Application.Contracts.ProgramManager;
|
||||
using Shared.Contracts.PmUser;
|
||||
using Shared.Contracts.PmUser.Commands;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
|
||||
using Shared.Contracts.PmUser.Queries;
|
||||
|
||||
//using AccountManagement.Domain.RoleAgg;
|
||||
|
||||
@@ -60,9 +61,10 @@ public class AccountApplication : IAccountApplication
|
||||
private readonly IPmUserRepository _pmUserRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IPmUserQueryService _pmUserQueryService;
|
||||
private readonly IPmUserCommandService _pmUserCommandService;
|
||||
|
||||
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, IPmUserRepository pmUserRepository, IPmUserQueryService pmUserQueryService)
|
||||
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, IPmUserQueryService pmUserQueryService, IPmUserCommandService pmUserCommandService)
|
||||
{
|
||||
_authHelper = authHelper;
|
||||
_roleRepository = roleRepository;
|
||||
@@ -78,6 +80,7 @@ public class AccountApplication : IAccountApplication
|
||||
_unitOfWork = unitOfWork;
|
||||
_pmUserRepository = pmUserRepository;
|
||||
_pmUserQueryService = pmUserQueryService;
|
||||
_pmUserCommandService = pmUserCommandService;
|
||||
_fileUploader = fileUploader;
|
||||
_passwordHasher = passwordHasher;
|
||||
_accountRepository = accountRepository;
|
||||
@@ -168,41 +171,17 @@ public class AccountApplication : IAccountApplication
|
||||
|
||||
if (command.IsProgramManagerUser)
|
||||
{
|
||||
|
||||
try
|
||||
var pmUserRoles = command.UserRoles.Where(x => x > 0).ToList();
|
||||
var createPm = await _pmUserCommandService.Create(new CreatePmUserDto(command.Fullname, command.Username, account.Password, command.Mobile,
|
||||
null, account.id, pmUserRoles));
|
||||
if (!createPm.isSuccess)
|
||||
{
|
||||
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("خطا در ایجاد کاربر پروگرام منیجر");
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("خطا در ویرایش کاربر پروگرام منیجر");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//var url = "api/user/create";
|
||||
//var key = SecretKeys.ProgramManagerInternalApi;
|
||||
|
||||
@@ -287,31 +266,27 @@ public class AccountApplication : IAccountApplication
|
||||
// $"api/user/{account.id}",
|
||||
// key
|
||||
//);
|
||||
var userResult = _pmUserRepository.GetByPmUsertoEditbyAccountId(account.id).GetAwaiter().GetResult();
|
||||
|
||||
var userResult =await _pmUserQueryService.GetPmUserDataByAccountId(account.id);
|
||||
|
||||
var pmUserRoles = command.UserRoles.Where(x => x > 0).ToList();
|
||||
|
||||
//اگر کاربر در پروگرام منیجر قبلا ایجاد شده
|
||||
if (userResult != null)
|
||||
if (userResult.Id >0)
|
||||
{
|
||||
if (!command.UserRoles.Any())
|
||||
{
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("حداقل یک نقش باید انتخاب شود");
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
var editPm =await _pmUserCommandService.Edit(new EditPmUserDto(command.Fullname, command.Username, command.Mobile, account.id, pmUserRoles,
|
||||
command.IsProgramManagerUser));
|
||||
if (!editPm.isSuccess)
|
||||
{
|
||||
_unitOfWork.RollbackAccountContext();
|
||||
return operation.Failed("خطا در ویرایش کاربر پروگرام منیجر");
|
||||
}
|
||||
|
||||
//var parameters = new EditUserCommand(
|
||||
// command.Fullname,
|
||||
// command.Username,
|
||||
@@ -352,39 +327,19 @@ public class AccountApplication : IAccountApplication
|
||||
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 => !string.IsNullOrWhiteSpace(x.Mobile) && x.Mobile == command.Mobile))
|
||||
|
||||
var createPm = await _pmUserCommandService.Create(new CreatePmUserDto(command.Fullname, command.Username, account.Password, command.Mobile,
|
||||
null, account.id, pmUserRoles));
|
||||
if (!createPm.isSuccess)
|
||||
{
|
||||
_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(
|
||||
|
||||
Reference in New Issue
Block a user