using CoreModels.Enums.Department;
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
{
///
/// Реализация интерфейса IClassroomService
///
public class ClassroomService :
AbstractGenerticEntityService,
IClassroomService
{
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, ClassroomSetBindingModel model) => OperationResultModel.Success(null);
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, Classroom entity, ClassroomGetBindingModel model) => OperationResultModel.Success(null);
protected override IQueryable AdditionalCheckingWhenReadingList(IQueryable query, ClassroomGetBindingModel model)
{
if (model.UseInSchedule.HasValue)
{
query = query.Where(x => x.ClassroomType == ClassroomType.Дисплейный || x.ClassroomType == ClassroomType.Лекционный ||
x.ClassroomType == ClassroomType.Обычный);
}
if (model.EmployeeId.HasValue)
{
query = query.Where(x => x.EmployeeId == model.EmployeeId.Value);
}
return query;
}
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, ClassroomSetBindingModel model) => OperationResultModel.Success(null);
protected override void AdditionalDeleting(DbContext context, Classroom entity, ClassroomGetBindingModel model) { }
protected override Classroom GetUniqueEntity(ClassroomSetBindingModel model, DbContext context) => context.Set().FirstOrDefault(x => x.Number == model.Number && x.Id != model.Id);
protected override IQueryable IncludingWhenReading(IQueryable query) => query.Include(x => x.Employee);
protected override IQueryable OrderingWhenReading(IQueryable query) => query.OrderBy(x => x.Number);
}
}