Update pmUser and create completed
This commit is contained in:
@@ -27,7 +27,8 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Shared.Contracts.PmRole.Commands;
|
||||
using Shared.Contracts.PmRole.Queries;
|
||||
using Shared.Contracts.PmUser;
|
||||
using Shared.Contracts.PmUser.Commands;
|
||||
using Shared.Contracts.PmUser.Queries;
|
||||
|
||||
namespace GozareshgirProgramManager.Infrastructure;
|
||||
|
||||
@@ -96,6 +97,7 @@ public static class DependencyInjection
|
||||
|
||||
services.AddTransient<IPmRoleCommandService, PmRoleCommandService>();
|
||||
services.AddTransient<IPmUserQueryService, PmUserQueryService>();
|
||||
services.AddTransient<IPmUserCommandService, PmUserCommandService>();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using GozareshgirProgramManager.Application.Modules.Users.Commands.CreateUser;
|
||||
using GozareshgirProgramManager.Application.Modules.Users.Commands.EditUser;
|
||||
using MediatR;
|
||||
using Shared.Contracts.PmUser.Commands;
|
||||
|
||||
namespace GozareshgirProgramManager.Infrastructure.Services.User;
|
||||
|
||||
public class PmUserCommandService : IPmUserCommandService
|
||||
{
|
||||
public readonly IMediator _mediator;
|
||||
|
||||
public PmUserCommandService(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
public async Task<(bool isSuccess, string pmUserDto)> Create(CreatePmUserDto command)
|
||||
{
|
||||
var request = new CreateUserCommand(command.FullName, command.UserName, command.Password, command.Mobile,
|
||||
command.Email, command.AccountId, command.Roles);
|
||||
|
||||
var res = await _mediator.Send(request);
|
||||
return (res.IsSuccess, res.ErrorMessage);
|
||||
}
|
||||
|
||||
public async Task<(bool isSuccess, string pmUserDto)> Edit(EditPmUserDto command)
|
||||
{
|
||||
var request = new EditUserCommand(command.FullName, command.UserName, command.Mobile, command.AccountId,
|
||||
command.Roles, command.IsActive);
|
||||
|
||||
var res = await _mediator.Send(request);
|
||||
return (res.IsSuccess, res.ErrorMessage);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Diagnostics;
|
||||
using GozareshgirProgramManager.Application.Modules.Users.Queries.GetSingleUser;
|
||||
using MediatR;
|
||||
using Shared.Contracts.PmUser;
|
||||
using Shared.Contracts.PmUser.Queries;
|
||||
using RoleListDto = Shared.Contracts.PmUser.Queries.RoleListDto;
|
||||
|
||||
namespace GozareshgirProgramManager.Infrastructure.Services.User;
|
||||
|
||||
@@ -19,4 +21,35 @@ public class PmUserQueryService : IPmUserQueryService
|
||||
var result = await _mediator.Send(query);
|
||||
return result.Data?.Id ?? null;
|
||||
}
|
||||
|
||||
public async Task<GetPmUserDto> GetPmUserDataByAccountId(long accountId)
|
||||
{
|
||||
var query = new GetSingleUserQuery(accountId.ToString());
|
||||
var result = await _mediator.Send(query);
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
var RoleDto = result.Data?.RoleListDto.Select(x => new RoleListDto()
|
||||
{
|
||||
RoleName = x.RoleName,
|
||||
RoleId = x.RoleId,
|
||||
Permissions = x.Permissions
|
||||
}).ToList();
|
||||
var res = new GetPmUserDto()
|
||||
{
|
||||
IsActive = result.Data.IsActive,
|
||||
AccountId = result.Data.AccountId,
|
||||
Id = result.Data.Id,
|
||||
Roles = result.Data.Roles,
|
||||
RoleListDto = RoleDto,
|
||||
};
|
||||
|
||||
return res;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new GetPmUserDto();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user