forked from ddrilling/AsbCloudServer
CS2-133: Fixed CRUD operations over Permissions
This commit is contained in:
parent
17db1218cc
commit
d94b2e685e
@ -4,5 +4,6 @@
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class PermissionInfoDto : IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
}
|
||||
}
|
@ -66,7 +66,6 @@ namespace AsbCloudInfrastructure
|
||||
// admin crud services:
|
||||
services.AddTransient<ICrudService<WellDto>, CrudServiceBase<WellDto, Well>>();
|
||||
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>();
|
||||
services.AddTransient<ICrudService<PermissionInfoDto>, CrudServiceBase<PermissionInfoDto, Permission>>();
|
||||
services.AddTransient<ICrudService<DrillParamsDto>, DrillParamsService>();
|
||||
services.AddTransient<ICrudService<DepositDto>, CrudServiceBase<DepositDto, Deposit>>();
|
||||
services.AddTransient<ICrudService<CompanyDto>, CrudServiceBase<CompanyDto, Company>>();
|
||||
|
@ -36,8 +36,18 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
public async Task<int> InsertRangeAsync(IEnumerable<PermissionDto> dtos, CancellationToken token)
|
||||
{
|
||||
var entities = dtos.Select(Convert);
|
||||
return (await cachePermission.InsertAsync(entities, token))?.Count()??0;
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
var entity = Convert(dto);
|
||||
var insertedEntity = cachePermission.Insert(entity);
|
||||
cacheUserRolePermission.Insert(new RelationUserRolePermission()
|
||||
{
|
||||
IdPermission = insertedEntity.Id,
|
||||
IdUserRole = dto.IdUserRole
|
||||
});
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public async Task<int> UpdateAsync(PermissionDto dto, CancellationToken token)
|
||||
@ -48,10 +58,12 @@ namespace AsbCloudInfrastructure.Services
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Task<int> DeleteAsync(int idUserRole, int idPermission, CancellationToken token)
|
||||
public async Task<int> DeleteAsync(int idUserRole, int idPermission, CancellationToken token)
|
||||
{
|
||||
bool predicate(RelationUserRolePermission p) => p.IdUserRole == idUserRole && p.IdPermission == idPermission;
|
||||
return DeleteAsync(predicate, token);
|
||||
await DeleteAsync(predicate, token);
|
||||
cachePermission.Remove(p => p.Id == idPermission);
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Task<int> DeleteAllByRoleAsync(int idUserRole, CancellationToken token)
|
||||
|
@ -46,14 +46,14 @@ namespace AsbCloudWebApi.Controllers
|
||||
public async Task<IActionResult> InsertRangeAsync(IEnumerable<PermissionDto> dtos,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var result = await permissionService.InsertRangeAsync(dtos, token);
|
||||
var result =await permissionService.InsertRangeAsync(dtos, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обновляет разрешение для роли
|
||||
/// </summary>
|
||||
/// <param name="dto"> Объект разрешения для справочника </param>
|
||||
/// <param name="dto"> Объект разрешения </param>
|
||||
/// <param name="token"> Токен отмены задачи </param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
|
@ -1,17 +0,0 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
[Route("api/admin/permissionInfo")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class AdminPermissionInfoController : CrudController<PermissionInfoDto, ICrudService<PermissionInfoDto>>
|
||||
{
|
||||
public AdminPermissionInfoController(ICrudService<PermissionInfoDto> permissionInfoService)
|
||||
:base(permissionInfoService)
|
||||
{}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user