DepartmentProject/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/Implementations/AbstractGenerticEntityService/DisciplineBlockService.cs

46 lines
2.5 KiB
C#

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