using CoreDatabase;
using CoreDatabase.Models.Department;
using DepartmentContract.BindingModels;
using DepartmentContract.Services.IGenericEntityService;
using DepartmentContract.ViewModels;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using ToolsModule.Enums;
using ToolsModule.Models;
namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService
{
///
/// Реализация IDisciplineBlockService
///
public class DisciplineBlockService :
AbstractGenerticEntityService,
IDisciplineBlockService
{
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, DisciplineBlockSetBindingModel model) => OperationResultModel.Success(null);
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, DisciplineBlock entity, DisciplineBlockGetBindingModel model)
{
if (context.Set().Any(x => x.DisciplineBlockId == model.Id && !x.IsDeleted))
{
return OperationResultModel.Error("Error:", "Есть дисциплины, относящиеся к этому блоку", ResultServiceStatusCode.ExsistItem);
}
if (context.Set().Any(x => x.DisciplineBlockId == model.Id && !x.IsDeleted))
{
return OperationResultModel.Error("Error:", "Есть нормы времени, относящиеся к этому блоку", ResultServiceStatusCode.ExsistItem);
}
return OperationResultModel.Success(null);
}
protected override IQueryable AdditionalCheckingWhenReadingList(IQueryable query, DisciplineBlockGetBindingModel model) => query;
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, DisciplineBlockSetBindingModel model) => OperationResultModel.Success(null);
protected override void AdditionalDeleting(DbContext context, DisciplineBlock entity, DisciplineBlockGetBindingModel model) { }
protected override DisciplineBlock GetUniqueEntity(DisciplineBlockSetBindingModel model, DbContext context) => context.Set().FirstOrDefault(x => x.Title == model.Title && x.Id != model.Id);
protected override IQueryable IncludingWhenReading(IQueryable query) => query;
protected override IQueryable OrderingWhenReading(IQueryable query) => query.OrderBy(x => x.DisciplineBlockOrder);
}
}