2021-03-26 20:09:52 +04:00
|
|
|
|
using DatabaseCore;
|
|
|
|
|
using DatabaseCore.Models.Security;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2021-03-28 19:15:55 +04:00
|
|
|
|
using ModuleTools.Models;
|
2021-03-26 20:09:52 +04:00
|
|
|
|
using SecurityBusinessLogic.BindingModels;
|
|
|
|
|
using SecurityBusinessLogic.Interfaces;
|
|
|
|
|
using SecurityBusinessLogic.ViewModels;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2021-04-01 21:30:29 +04:00
|
|
|
|
namespace SecurityDatabaseImplementation.Implementations
|
2021-03-26 20:09:52 +04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Реализация IAccessService
|
|
|
|
|
/// </summary>
|
2021-04-05 10:08:49 +04:00
|
|
|
|
public class AccessService :
|
|
|
|
|
AbstractGenerticEntityService<AccessGetBindingModel, AccessSetBindingModel, Access, AccessListViewModel, AccessViewModel>,
|
|
|
|
|
IAccessService
|
2021-03-26 20:09:52 +04:00
|
|
|
|
{
|
2021-04-05 10:08:49 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, AccessSetBindingModel model) => OperationResultModel.Success(null);
|
2021-03-26 20:09:52 +04:00
|
|
|
|
|
2021-04-05 10:08:49 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, AccessGetBindingModel model) { return OperationResultModel.Success(null); }
|
2021-03-26 20:09:52 +04:00
|
|
|
|
|
2021-04-05 10:08:49 +04:00
|
|
|
|
protected override IQueryable<Access> AdditionalCheckingWhenReadingList(IQueryable<Access> query, AccessGetBindingModel model)
|
2021-03-26 20:09:52 +04:00
|
|
|
|
{
|
|
|
|
|
if (model.RoleId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.RoleId == model.RoleId);
|
|
|
|
|
}
|
2021-04-05 10:08:49 +04:00
|
|
|
|
return query;
|
2021-03-26 20:09:52 +04:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-05 10:08:49 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, AccessSetBindingModel model) => OperationResultModel.Success(null);
|
2021-03-26 20:09:52 +04:00
|
|
|
|
|
2021-04-05 10:08:49 +04:00
|
|
|
|
protected override void AdditionalDeleting(DbContext context, AccessGetBindingModel model) { }
|
2021-03-26 20:09:52 +04:00
|
|
|
|
|
2021-04-05 10:08:49 +04:00
|
|
|
|
protected override Access GetUniqueEntity(AccessSetBindingModel model, DbContext context) =>
|
|
|
|
|
context.Set<Access>().FirstOrDefault(x => x.AccessOperation == model.AccessOperation && x.RoleId == model.RoleId && x.AccessType == model.AccessType && x.Id != model.Id);
|
2021-03-26 20:09:52 +04:00
|
|
|
|
|
2021-04-05 10:08:49 +04:00
|
|
|
|
protected override IQueryable<Access> IncludingWhenReading(IQueryable<Access> query) => query.Include(x => x.Role);
|
|
|
|
|
|
|
|
|
|
protected override IQueryable<Access> OrderingWhenReading(IQueryable<Access> query) =>
|
|
|
|
|
query.OrderBy(x => x.Role.RoleName).ThenBy(x => x.AccessOperation).ThenBy(x => x.AccessType);
|
2021-03-26 20:09:52 +04:00
|
|
|
|
}
|
|
|
|
|
}
|