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
{
///
/// Реализация IAccessService
///
public class AccessService :
AbstractGenerticEntityService,
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 AdditionalCheckingWhenReadingList(IQueryable 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().FirstOrDefault(x => x.AccessOperation == model.AccessOperation && x.RoleId == model.RoleId && x.AccessType == model.AccessType && x.Id != model.Id);
protected override IQueryable IncludingWhenReading(IQueryable query) => query.Include(x => x.Role);
protected override IQueryable OrderingWhenReading(IQueryable query) =>
query.OrderBy(x => x.Role.RoleName).ThenBy(x => x.AccessOperation).ThenBy(x => x.AccessType);
}
}