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

45 lines
2.0 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.Linq;
namespace DepartmentDatabaseImplementation.Implementations
{
/// <summary>
/// Реализация ITimeNormService
/// </summary>
public class TimeNormService :
AbstractGenerticEntityService<TimeNormGetBindingModel, TimeNormSetBindingModel, TimeNorm, TimeNormListViewModel, TimeNormViewModel>,
ITimeNormService
{
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, TimeNormSetBindingModel model) => OperationResultModel.Success(null);
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, TimeNorm entity, TimeNormGetBindingModel model)
{
return OperationResultModel.Success(null);
}
protected override IQueryable<TimeNorm> AdditionalCheckingWhenReadingList(IQueryable<TimeNorm> query, TimeNormGetBindingModel model)
{
if (model.DisciplineBlockId.HasValue)
{
query = query.Where(x => x.DisciplineBlockId == model.DisciplineBlockId.Value);
}
return query;
}
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, TimeNormSetBindingModel model) => OperationResultModel.Success(null);
protected override void AdditionalDeleting(DbContext context, TimeNorm entity, TimeNormGetBindingModel model) { }
protected override TimeNorm GetUniqueEntity(TimeNormSetBindingModel model, DbContext context) => context.Set<TimeNorm>().FirstOrDefault(x => x.TimeNormName == model.TimeNormName && x.TimeNormShortName == model.TimeNormShortName && x.Id != model.Id);
protected override IQueryable<TimeNorm> IncludingWhenReading(IQueryable<TimeNorm> query) => query.Include(x => x.DisciplineBlock);
protected override IQueryable<TimeNorm> OrderingWhenReading(IQueryable<TimeNorm> query) => query.OrderBy(x => x.TimeNormOrder);
}
}