using DatabaseCore;
using DatabaseCore.Models.Department;
using DepartmentBusinessLogic.BindingModels;
using DepartmentBusinessLogic.Interfaces;
using DepartmentBusinessLogic.ViewModels;
using Microsoft.EntityFrameworkCore;
using ModuleTools.Enums;
using ModuleTools.Models;
using System.Linq;
namespace DepartmentDatabaseImplementation.Implementations
{
///
/// Реализация IOrderService
///
public class OrderService :
AbstractGenerticEntityService,
IOrderService
{
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, OrderSetBindingModel model) => OperationResultModel.Success(null);
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, Order entity, OrderGetBindingModel model)
{
if (context.Set().Any(x => x.OrderId == model.Id && !x.IsDeleted))
{
return OperationResultModel.Error("Error:", "Есть записи приказа по студентам, относящиеся к этому приказу", ResultServiceStatusCode.ExsistItem);
}
return OperationResultModel.Success(null);
}
protected override IQueryable AdditionalCheckingWhenReadingList(IQueryable query, OrderGetBindingModel model) => query;
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, OrderSetBindingModel model) => OperationResultModel.Success(null);
protected override void AdditionalDeleting(DbContext context, Order entity, OrderGetBindingModel model) { }
protected override Order GetUniqueEntity(OrderSetBindingModel model, DbContext context) => context.Set().FirstOrDefault(x => x.OrderNumber == model.OrderNumber && x.Id != model.Id);
protected override IQueryable IncludingWhenReading(IQueryable query) => query;
protected override IQueryable OrderingWhenReading(IQueryable query) => query.OrderBy(x => x.OrderDate).ThenBy(x => x.OrderNumber);
}
}