2022-03-18 22:55:48 +04:00
|
|
|
|
using CoreDatabase;
|
|
|
|
|
using CoreDatabase.Models.Department;
|
2022-03-19 22:48:13 +04:00
|
|
|
|
using DepartmentContract.BindingModels;
|
|
|
|
|
using DepartmentContract.Services.IGenericEntityService;
|
|
|
|
|
using DepartmentContract.ViewModels;
|
2021-04-13 12:52:45 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-03-19 22:48:13 +04:00
|
|
|
|
using System.Linq;
|
2022-03-20 10:10:44 +04:00
|
|
|
|
using ToolsModule.ManagmentEntity;
|
|
|
|
|
using ToolsModule.ManagmentExtension;
|
2021-04-13 12:52:45 +04:00
|
|
|
|
|
2022-03-19 22:48:13 +04:00
|
|
|
|
namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService
|
2021-04-13 12:52:45 +04:00
|
|
|
|
{
|
2022-03-19 22:48:13 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Реализация IOrderService
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class OrderService :
|
2021-04-13 12:52:45 +04:00
|
|
|
|
AbstractGenerticEntityService<OrderGetBindingModel, OrderSetBindingModel, Order, OrderListViewModel, OrderViewModel>,
|
|
|
|
|
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<OrderStudentRecord>().Any(x => x.OrderId == model.Id && !x.IsDeleted))
|
|
|
|
|
{
|
|
|
|
|
return OperationResultModel.Error("Error:", "Есть записи приказа по студентам, относящиеся к этому приказу", ResultServiceStatusCode.ExsistItem);
|
|
|
|
|
}
|
|
|
|
|
return OperationResultModel.Success(null);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 15:14:35 +04:00
|
|
|
|
protected override IQueryable<Order> AdditionalCheckingWhenReadingList(IQueryable<Order> query, OrderGetBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if(model.OrderDate.HasValue && model.OrderNumber.IsNotEmpty())
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.OrderNumber == model.OrderNumber && x.OrderDate == model.OrderDate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return query;
|
|
|
|
|
}
|
2021-04-13 12:52:45 +04:00
|
|
|
|
|
|
|
|
|
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<Order>().FirstOrDefault(x => x.OrderNumber == model.OrderNumber && x.Id != model.Id);
|
|
|
|
|
|
|
|
|
|
protected override IQueryable<Order> IncludingWhenReading(IQueryable<Order> query) => query;
|
|
|
|
|
|
|
|
|
|
protected override IQueryable<Order> OrderingWhenReading(IQueryable<Order> query) => query.OrderBy(x => x.OrderDate).ThenBy(x => x.OrderNumber);
|
|
|
|
|
|
2021-04-27 17:09:03 +04:00
|
|
|
|
protected override bool AdditionalCheckForSingleGet(OrderGetBindingModel model)
|
|
|
|
|
{
|
2021-08-20 18:28:34 +04:00
|
|
|
|
if (model.OrderNumber.IsNotEmpty())
|
2021-04-27 17:09:03 +04:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return base.AdditionalCheckForSingleGet(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Order GetSingleRecord(IQueryable<Order> list, OrderGetBindingModel model)
|
|
|
|
|
{
|
2021-08-20 18:28:34 +04:00
|
|
|
|
if (model.OrderNumber.IsNotEmpty())
|
2021-04-27 17:09:03 +04:00
|
|
|
|
{
|
2021-08-20 18:28:34 +04:00
|
|
|
|
return list.FirstOrDefault(x => x.OrderNumber == model.OrderNumber);
|
2021-04-27 17:09:03 +04:00
|
|
|
|
}
|
|
|
|
|
return base.GetSingleRecord(list, model);
|
|
|
|
|
}
|
2021-04-13 12:52:45 +04:00
|
|
|
|
}
|
|
|
|
|
}
|