2021-04-03 19:03:56 +04:00
|
|
|
|
using DatabaseCore;
|
|
|
|
|
using DatabaseCore.Models.Department;
|
|
|
|
|
using DepartmentBusinessLogic.BindingModels;
|
|
|
|
|
using DepartmentBusinessLogic.Interfaces;
|
|
|
|
|
using DepartmentBusinessLogic.ViewModels;
|
2021-04-05 12:25:10 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-03-18 22:38:52 +04:00
|
|
|
|
using ToolsModule.Enums;
|
|
|
|
|
using ToolsModule.Models;
|
2021-04-03 19:03:56 +04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace DepartmentDatabaseImplementation.Implementations
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Реализация IDisciplineBlockService
|
|
|
|
|
/// </summary>
|
2021-04-05 12:25:10 +04:00
|
|
|
|
public class DisciplineBlockService :
|
|
|
|
|
AbstractGenerticEntityService<DisciplineBlockGetBindingModel, DisciplineBlockSetBindingModel, DisciplineBlock, DisciplineBlockListViewModel, DisciplineBlockViewModel>,
|
|
|
|
|
IDisciplineBlockService
|
2021-04-03 19:03:56 +04:00
|
|
|
|
{
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, DisciplineBlockSetBindingModel model) => OperationResultModel.Success(null);
|
2021-04-03 19:03:56 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, DisciplineBlock entity, DisciplineBlockGetBindingModel model)
|
2021-04-03 19:03:56 +04:00
|
|
|
|
{
|
2021-04-05 12:25:10 +04:00
|
|
|
|
if (context.Set<Discipline>().Any(x => x.DisciplineBlockId == model.Id && !x.IsDeleted))
|
2021-04-03 23:46:48 +04:00
|
|
|
|
{
|
|
|
|
|
return OperationResultModel.Error("Error:", "Есть дисциплины, относящиеся к этому блоку", ResultServiceStatusCode.ExsistItem);
|
2021-04-06 22:07:11 +04:00
|
|
|
|
}
|
|
|
|
|
if (context.Set<TimeNorm>().Any(x => x.DisciplineBlockId == model.Id && !x.IsDeleted))
|
|
|
|
|
{
|
|
|
|
|
return OperationResultModel.Error("Error:", "Есть нормы времени, относящиеся к этому блоку", ResultServiceStatusCode.ExsistItem);
|
2021-04-03 23:46:48 +04:00
|
|
|
|
}
|
2021-04-05 12:25:10 +04:00
|
|
|
|
return OperationResultModel.Success(null);
|
2021-04-03 19:03:56 +04:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override IQueryable<DisciplineBlock> AdditionalCheckingWhenReadingList(IQueryable<DisciplineBlock> query, DisciplineBlockGetBindingModel model) => query;
|
2021-04-03 19:03:56 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, DisciplineBlockSetBindingModel model) => OperationResultModel.Success(null);
|
2021-04-03 19:03:56 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override void AdditionalDeleting(DbContext context, DisciplineBlock entity, DisciplineBlockGetBindingModel model) { }
|
2021-04-03 19:03:56 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override DisciplineBlock GetUniqueEntity(DisciplineBlockSetBindingModel model, DbContext context) => context.Set<DisciplineBlock>().FirstOrDefault(x => x.Title == model.Title && x.Id != model.Id);
|
2021-04-03 19:03:56 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override IQueryable<DisciplineBlock> IncludingWhenReading(IQueryable<DisciplineBlock> query) => query;
|
2021-04-03 19:03:56 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override IQueryable<DisciplineBlock> OrderingWhenReading(IQueryable<DisciplineBlock> query) => query.OrderBy(x => x.DisciplineBlockOrder);
|
2021-04-03 19:03:56 +04:00
|
|
|
|
}
|
|
|
|
|
}
|