using DatabaseCore;
using DatabaseCore.Models.Department;
using DepartmentBusinessLogic.BindingModels;
using DepartmentBusinessLogic.Interfaces;
using DepartmentBusinessLogic.ViewModels;
using Microsoft.EntityFrameworkCore;
using ToolsModule.Models;
using System.Linq;
namespace DepartmentDatabaseImplementation.Implementations
{
///
/// Реализация ILecturerPostService
///
public class LecturerPostService :
AbstractGenerticEntityService,
ILecturerPostService
{
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, LecturerPostSetBindingModel model) => OperationResultModel.Success(null);
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, LecturerPost entity, LecturerPostGetBindingModel model) => OperationResultModel.Success(null);
protected override IQueryable AdditionalCheckingWhenReadingList(IQueryable query, LecturerPostGetBindingModel model)
{
if (model.PostId.HasValue)
{
query = query.Where(x => x.PostId == model.PostId);
}
if (model.LecturerId.HasValue)
{
query = query.Where(x => x.LecturerId == model.LecturerId);
}
return query;
}
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, LecturerPostSetBindingModel model) => OperationResultModel.Success(null);
protected override void AdditionalDeleting(DbContext context, LecturerPost entity, LecturerPostGetBindingModel model) { }
protected override LecturerPost GetUniqueEntity(LecturerPostSetBindingModel model, DbContext context) => context.Set().FirstOrDefault(x => x.LecturerId == model.LecturerId && x.PostId == model.PostId && x.Id != model.Id);
protected override IQueryable IncludingWhenReading(IQueryable query) => query.Include(x => x.Post).Include(x => x.Lecturer);
protected override IQueryable OrderingWhenReading(IQueryable query) => query.OrderBy(x => x.Lecturer.LastName);
}
}