create PmRole Completed

This commit is contained in:
SamSys
2025-12-13 18:25:19 +03:30
parent f2293934d4
commit c9d582877b
26 changed files with 2010 additions and 398 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}
}