2022-03-18 21:34:16 +04:00
|
|
|
|
using CoreModels.Enums.Department;
|
|
|
|
|
using DatabaseCore;
|
2021-04-03 13:41:19 +04:00
|
|
|
|
using DatabaseCore.Models.Department;
|
|
|
|
|
using DepartmentBusinessLogic.BindingModels;
|
|
|
|
|
using DepartmentBusinessLogic.Interfaces;
|
|
|
|
|
using DepartmentBusinessLogic.ViewModels;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using ModuleTools.Models;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace DepartmentDatabaseImplementation.Implementations
|
|
|
|
|
{
|
2022-03-18 21:34:16 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Реализация интерфейса IClassroomService
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ClassroomService :
|
2021-04-05 12:25:10 +04:00
|
|
|
|
AbstractGenerticEntityService<ClassroomGetBindingModel, ClassroomSetBindingModel, Classroom, ClassroomListViewModel, ClassroomViewModel>,
|
|
|
|
|
IClassroomService
|
2021-04-03 13:41:19 +04:00
|
|
|
|
{
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, ClassroomSetBindingModel model) => OperationResultModel.Success(null);
|
2021-04-03 13:41:19 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, Classroom entity, ClassroomGetBindingModel model) => OperationResultModel.Success(null);
|
2021-04-03 13:41:19 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override IQueryable<Classroom> AdditionalCheckingWhenReadingList(IQueryable<Classroom> query, ClassroomGetBindingModel model)
|
2021-04-03 13:41:19 +04:00
|
|
|
|
{
|
|
|
|
|
if (model.UseInSchedule.HasValue)
|
|
|
|
|
{
|
2022-03-18 21:34:16 +04:00
|
|
|
|
query = query.Where(x => x.ClassroomType == ClassroomType.Дисплейный || x.ClassroomType == ClassroomType.Лекционный ||
|
|
|
|
|
x.ClassroomType == ClassroomType.Обычный);
|
2021-04-03 13:41:19 +04:00
|
|
|
|
}
|
|
|
|
|
if (model.EmployeeId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.EmployeeId == model.EmployeeId.Value);
|
|
|
|
|
}
|
2021-04-05 12:25:10 +04:00
|
|
|
|
return query;
|
2021-04-03 13:41:19 +04:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, ClassroomSetBindingModel model) => OperationResultModel.Success(null);
|
2021-04-03 13:41:19 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override void AdditionalDeleting(DbContext context, Classroom entity, ClassroomGetBindingModel model) { }
|
2021-04-03 13:41:19 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override Classroom GetUniqueEntity(ClassroomSetBindingModel model, DbContext context) => context.Set<Classroom>().FirstOrDefault(x => x.Number == model.Number && x.Id != model.Id);
|
2021-04-03 13:41:19 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override IQueryable<Classroom> IncludingWhenReading(IQueryable<Classroom> query) => query.Include(x => x.Employee);
|
|
|
|
|
|
|
|
|
|
protected override IQueryable<Classroom> OrderingWhenReading(IQueryable<Classroom> query) => query.OrderBy(x => x.Number);
|
2021-04-03 13:41:19 +04:00
|
|
|
|
}
|
|
|
|
|
}
|