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
{
///
/// Реализация ITimeNormService
///
public class TimeNormService :
AbstractGenerticEntityService,
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 AdditionalCheckingWhenReadingList(IQueryable 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().FirstOrDefault(x => x.TimeNormName == model.TimeNormName && x.TimeNormShortName == model.TimeNormShortName && x.Id != model.Id);
protected override IQueryable IncludingWhenReading(IQueryable query) => query.Include(x => x.DisciplineBlock);
protected override IQueryable OrderingWhenReading(IQueryable query) => query.OrderBy(x => x.TimeNormOrder);
}
}