DepartmentProject/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/Implementations/EducationDirectionService.cs

43 lines
2.2 KiB
C#

using DatabaseCore;
using DatabaseCore.Models.Department;
using DepartmentBusinessLogic.BindingModels;
using DepartmentBusinessLogic.Interfaces;
using DepartmentBusinessLogic.ViewModels;
using Microsoft.EntityFrameworkCore;
using ModuleTools.Models;
using System;
using System.Linq;
namespace DepartmentDatabaseImplementation.Implementations
{
/// <summary>
/// Реализация интерфейса IEducationDirectionService
/// </summary>
public class EducationDirectionService :
AbstractGenerticEntityService<EducationDirectionGetBindingModel, EducationDirectionSetBindingModel, EducationDirection, EducationDirectionListViewModel, EducationDirectionViewModel>,
IEducationDirectionService
{
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, EducationDirectionSetBindingModel model) => OperationResultModel.Success(null);
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, EducationDirection entity, EducationDirectionGetBindingModel model) => OperationResultModel.Success(null);
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) { }
protected override EducationDirection GetUniqueEntity(EducationDirectionSetBindingModel model, DbContext context) => context.Set<EducationDirection>().FirstOrDefault(x => x.Title == model.Title && x.Profile == model.Profile && x.Id != model.Id);
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);
}
}