DepartmentProject/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/AbstractGenerticEntityService/AccessService.cs

44 lines
2.0 KiB
C#

using CoreDatabase;
using CoreDatabase.Models.Security;
using Microsoft.EntityFrameworkCore;
using SecurityContract.BindingModels;
using SecurityContract.Services.IGenericEntityService;
using SecurityContract.ViewModels;
using System.Linq;
using ToolsModule.ManagmentEntity;
namespace SecurityDatabaseImplementation.Implementations.AbstractGenerticEntityService
{
/// <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);
}
}