2022-03-18 22:55:48 +04:00
|
|
|
|
using CoreDatabase;
|
|
|
|
|
using CoreDatabase.Models.Department;
|
2021-04-03 19:03:56 +04:00
|
|
|
|
using DepartmentBusinessLogic.BindingModels;
|
|
|
|
|
using DepartmentBusinessLogic.Interfaces;
|
|
|
|
|
using DepartmentBusinessLogic.ViewModels;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-03-18 22:38:52 +04:00
|
|
|
|
using ToolsModule.Enums;
|
|
|
|
|
using ToolsModule.Extensions;
|
|
|
|
|
using ToolsModule.Models;
|
2021-04-03 19:03:56 +04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace DepartmentDatabaseImplementation.Implementations
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Реализация IDisciplineService
|
|
|
|
|
/// </summary>
|
2021-04-05 12:25:10 +04:00
|
|
|
|
public class DisciplineService :
|
|
|
|
|
AbstractGenerticEntityService<DisciplineGetBindingModel, DisciplineSetBindingModel, Discipline, DisciplineListViewModel, DisciplineViewModel>,
|
|
|
|
|
IDisciplineService
|
2021-04-03 19:03:56 +04:00
|
|
|
|
{
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, DisciplineSetBindingModel model) => OperationResultModel.Success(null);
|
2021-04-03 19:03:56 +04:00
|
|
|
|
|
2021-04-06 22:07:11 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, Discipline entity, DisciplineGetBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (context.Set<AcademicPlanRecord>().Any(x => x.DisciplineId == model.Id && !x.IsDeleted))
|
|
|
|
|
{
|
|
|
|
|
return OperationResultModel.Error("Error:", "Есть записи учебного плана, относящиеся к этой дисциплине", ResultServiceStatusCode.ExsistItem);
|
|
|
|
|
}
|
|
|
|
|
return OperationResultModel.Success(null);
|
|
|
|
|
}
|
2021-04-03 19:03:56 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override IQueryable<Discipline> AdditionalCheckingWhenReadingList(IQueryable<Discipline> query, DisciplineGetBindingModel model)
|
2021-04-03 19:03:56 +04:00
|
|
|
|
{
|
|
|
|
|
if (model.DisciplineName.IsNotEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.DisciplineName.Contains(model.DisciplineName));
|
|
|
|
|
}
|
|
|
|
|
if (model.DisciplineBlockId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.DisciplineBlockId == model.DisciplineBlockId.Value);
|
|
|
|
|
}
|
2021-04-05 12:25:10 +04:00
|
|
|
|
return query;
|
2021-04-03 19:03:56 +04:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, DisciplineSetBindingModel 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, Discipline entity, DisciplineGetBindingModel model) { }
|
2021-04-03 19:03:56 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override Discipline GetUniqueEntity(DisciplineSetBindingModel model, DbContext context) => context.Set<Discipline>().FirstOrDefault(x => x.DisciplineName == model.DisciplineName && x.Id != model.Id);
|
2021-04-03 19:03:56 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override IQueryable<Discipline> IncludingWhenReading(IQueryable<Discipline> query) => query.Include(x => x.DisciplineBlock);
|
|
|
|
|
|
|
|
|
|
protected override IQueryable<Discipline> OrderingWhenReading(IQueryable<Discipline> query) => query.OrderBy(x => x.DisciplineBlock.DisciplineBlockOrder).ThenBy(x => x.DisciplineName);
|
2021-04-03 19:03:56 +04:00
|
|
|
|
}
|
|
|
|
|
}
|