44 lines
2.0 KiB
C#
44 lines
2.0 KiB
C#
using DatabaseCore;
|
|
using DatabaseCore.Models.Security;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using ModuleTools.Models;
|
|
using SecurityBusinessLogic.BindingModels;
|
|
using SecurityBusinessLogic.Interfaces;
|
|
using SecurityBusinessLogic.ViewModels;
|
|
using System.Linq;
|
|
|
|
namespace SecurityDatabaseImplementation.Implementations
|
|
{
|
|
/// <summary>
|
|
/// Реализация IAccessService
|
|
/// </summary>
|
|
public class AccessService :
|
|
AbstractGenerticEntityService<AccessGetBindingModel, AccessSetBindingModel, Access, AccessListViewModel, AccessViewModel>,
|
|
IAccessService
|
|
{
|
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, AccessSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, Access entity, AccessGetBindingModel model) { return OperationResultModel.Success(null); }
|
|
|
|
protected override IQueryable<Access> AdditionalCheckingWhenReadingList(IQueryable<Access> query, AccessGetBindingModel model)
|
|
{
|
|
if (model.RoleId.HasValue)
|
|
{
|
|
query = query.Where(x => x.RoleId == model.RoleId);
|
|
}
|
|
return query;
|
|
}
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, AccessSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override void AdditionalDeleting(DbContext context, Access entity, AccessGetBindingModel model) { }
|
|
|
|
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);
|
|
|
|
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);
|
|
}
|
|
} |