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-05 14:20:07 +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;
|
2021-04-05 14:20:07 +04:00
|
|
|
|
|
2022-03-19 22:48:13 +04:00
|
|
|
|
namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService
|
2021-04-05 14:20:07 +04:00
|
|
|
|
{
|
2022-03-19 22:48:13 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Реализация интерфейса IEducationDirectionService
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class EducationDirectionService :
|
2021-04-05 14:20:07 +04:00
|
|
|
|
AbstractGenerticEntityService<EducationDirectionGetBindingModel, EducationDirectionSetBindingModel, EducationDirection, EducationDirectionListViewModel, EducationDirectionViewModel>,
|
|
|
|
|
IEducationDirectionService
|
|
|
|
|
{
|
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, EducationDirectionSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
|
|
2021-04-06 22:07:11 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, EducationDirection entity, EducationDirectionGetBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (context.Set<AcademicPlan>().Any(x => x.EducationDirectionId == model.Id && !x.IsDeleted))
|
|
|
|
|
{
|
|
|
|
|
return OperationResultModel.Error("Error:", "Есть учебные планы, относящиеся к этому направлению", ResultServiceStatusCode.ExsistItem);
|
|
|
|
|
}
|
2021-04-27 18:04:01 +04:00
|
|
|
|
if (context.Set<StudentGroup>().Any(x => x.EducationDirectionId == model.Id && !x.IsDeleted))
|
|
|
|
|
{
|
|
|
|
|
return OperationResultModel.Error("Error:", "Есть учебные группы, относящиеся к этому направлению", ResultServiceStatusCode.ExsistItem);
|
|
|
|
|
}
|
2021-04-06 22:07:11 +04:00
|
|
|
|
return OperationResultModel.Success(null);
|
|
|
|
|
}
|
2021-04-05 14:20:07 +04:00
|
|
|
|
|
|
|
|
|
protected override IQueryable<EducationDirection> AdditionalCheckingWhenReadingList(IQueryable<EducationDirection> query, EducationDirectionGetBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model.LecturerId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.LecturerId == model.LecturerId.Value);
|
|
|
|
|
}
|
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, EducationDirectionSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
|
|
|
|
|
|
protected override void AdditionalDeleting(DbContext context, EducationDirection entity, EducationDirectionGetBindingModel model) { }
|
|
|
|
|
|
2022-03-29 13:33:32 +04:00
|
|
|
|
protected override EducationDirection GetUniqueEntity(EducationDirectionSetBindingModel model, IQueryable<EducationDirection> query) => query.FirstOrDefault(x => x.Title == model.Title && x.Profile == model.Profile && x.Id != model.Id);
|
2021-04-05 14:20:07 +04:00
|
|
|
|
|
|
|
|
|
protected override IQueryable<EducationDirection> IncludingWhenReading(IQueryable<EducationDirection> query) => query.Include(x => x.Lecturer);
|
|
|
|
|
|
|
|
|
|
protected override IQueryable<EducationDirection> OrderingWhenReading(IQueryable<EducationDirection> query) => query.OrderBy(x => x.Cipher);
|
|
|
|
|
}
|
|
|
|
|
}
|