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 { /// /// Реализация интерфейса IEducationDirectionService /// public class EducationDirectionService : AbstractGenerticEntityService, IEducationDirectionService { protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, EducationDirectionSetBindingModel model) => OperationResultModel.Success(null); protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, EducationDirection entity, EducationDirectionGetBindingModel model) { if (context.Set().Any(x => x.EducationDirectionId == model.Id && !x.IsDeleted)) { return OperationResultModel.Error("Error:", "Есть учебные планы, относящиеся к этому направлению", ResultServiceStatusCode.ExsistItem); } return OperationResultModel.Success(null); } protected override IQueryable AdditionalCheckingWhenReadingList(IQueryable 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) { } protected override EducationDirection GetUniqueEntity(EducationDirectionSetBindingModel model, IQueryable query) => query.FirstOrDefault(x => x.Title == model.Title && x.Profile == model.Profile && x.Id != model.Id); protected override IQueryable IncludingWhenReading(IQueryable query) => query.Include(x => x.Lecturer); protected override IQueryable OrderingWhenReading(IQueryable query) => query.OrderBy(x => x.Cipher); } }