DepartmentProject/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/Implementations/AbstractGenerticEntityService/ClassroomService.cs

48 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using CoreDatabase;
using CoreDatabase.Models.Department;
using CoreModels.Enums.Department;
using DepartmentContract.BindingModels;
using DepartmentContract.Services.IGenericEntityService;
using DepartmentContract.ViewModels;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using ToolsModule.ManagmentEntity;
namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService
{
/// <summary>
/// Реализация интерфейса IClassroomService
/// </summary>
public class ClassroomService :
AbstractGenerticEntityService<ClassroomGetBindingModel, ClassroomSetBindingModel, Classroom, ClassroomListViewModel, ClassroomViewModel>,
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<Classroom> AdditionalCheckingWhenReadingList(IQueryable<Classroom> 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, IQueryable<Classroom> query) => query.FirstOrDefault(x => x.Number == model.Number && x.Id != model.Id);
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);
}
}