create PmRole Completed
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using GozareshgirProgramManager.Application._Common.Models;
|
||||
using GozareshgirProgramManager.Application.Modules.Roles.Commands.CreateRole;
|
||||
using MediatR;
|
||||
using Shared.Contracts.PmRole.Commands;
|
||||
|
||||
namespace GozareshgirProgramManager.Infrastructure.Services.Role;
|
||||
|
||||
public class PmRoleCommandService: IPmRoleCommandService
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public PmRoleCommandService(IMediator mediator)
|
||||
{
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task<(bool, string)> Create(CreatePmRoleDto command)
|
||||
{
|
||||
var request = new CreateRoleCommand
|
||||
{
|
||||
RoleName = command.RoleName, Permissions = command.Permissions, GozareshgirRoleId = command.GozareshgirRoleId
|
||||
};
|
||||
var res = await _mediator.Send(request);
|
||||
return (res.IsSuccess, res.ErrorMessage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using GozareshgirProgramManager.Infrastructure.Persistence.Context;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Shared.Contracts.PmRole.Queries;
|
||||
|
||||
namespace GozareshgirProgramManager.Infrastructure.Services.Role;
|
||||
|
||||
public class PmRoleQueryService : IPmRoleQueryService
|
||||
{
|
||||
private readonly ProgramManagerDbContext _programManagerDbContext;
|
||||
|
||||
public PmRoleQueryService(ProgramManagerDbContext programManagerDbContext)
|
||||
{
|
||||
_programManagerDbContext = programManagerDbContext;
|
||||
}
|
||||
|
||||
public async Task<List<GetPmRolesDto>> GetPmRoleList(long? gozareshgirRoleId)
|
||||
{
|
||||
var query = _programManagerDbContext.Roles.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.Permissions.Select(x => x.Code).ToList()
|
||||
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user