using CoreDatabase;
using CoreDatabase.Models.Security;
using Microsoft.EntityFrameworkCore;
using SecurityContract.BindingModels;
using SecurityContract.Services.IGenericEntityService;
using SecurityContract.ViewModels;
using System.Linq;
using ToolsModule.Models;
namespace SecurityDatabaseImplementation.Implementations.AbstractGenerticEntityService
{
///
/// Реализация 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);
}
}