2022-03-18 22:55:48 +04:00
|
|
|
|
using CoreDatabase;
|
|
|
|
|
using CoreDatabase.Models.Department;
|
2022-03-19 22:48:13 +04:00
|
|
|
|
using DepartmentContract.BindingModels;
|
|
|
|
|
using DepartmentContract.Services.IGenericEntityService;
|
|
|
|
|
using DepartmentContract.ViewModels;
|
2021-04-03 19:03:56 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-03-19 22:48:13 +04:00
|
|
|
|
using System.Linq;
|
2022-03-20 10:10:44 +04:00
|
|
|
|
using ToolsModule.ManagmentEntity;
|
|
|
|
|
using ToolsModule.ManagmentExtension;
|
2021-04-03 19:03:56 +04:00
|
|
|
|
|
2022-03-19 22:48:13 +04:00
|
|
|
|
namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService
|
2021-04-03 19:03:56 +04:00
|
|
|
|
{
|
2022-03-19 22:48:13 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Реализация IDisciplineService
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class DisciplineService :
|
2021-04-05 12:25:10 +04:00
|
|
|
|
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);
|
|
|
|
|
}
|
2022-03-27 14:51:27 +04:00
|
|
|
|
if (model.BasicDepartmentId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.BasicDepartmentId == model.BasicDepartmentId.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
|
|
|
|
|
2022-03-29 13:33:32 +04:00
|
|
|
|
protected override Discipline GetUniqueEntity(DisciplineSetBindingModel model, IQueryable<Discipline> query) => query.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
|
|
|
|
}
|
|
|
|
|
}
|