70 lines
2.8 KiB
C#
70 lines
2.8 KiB
C#
using CoreDatabase;
|
|
using CoreDatabase.Models.Department;
|
|
using DepartmentContract.BindingModels;
|
|
using DepartmentContract.Services.IGenericEntityService;
|
|
using DepartmentContract.ViewModels;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Linq;
|
|
using ToolsModule.Enums;
|
|
using ToolsModule.Extensions;
|
|
using ToolsModule.Models;
|
|
|
|
namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService
|
|
{
|
|
/// <summary>
|
|
/// Реализация IOrderService
|
|
/// </summary>
|
|
public class OrderService :
|
|
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);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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);
|
|
|
|
protected override bool AdditionalCheckForSingleGet(OrderGetBindingModel model)
|
|
{
|
|
if (model.OrderNumber.IsNotEmpty())
|
|
{
|
|
return true;
|
|
}
|
|
return base.AdditionalCheckForSingleGet(model);
|
|
}
|
|
|
|
protected override Order GetSingleRecord(IQueryable<Order> list, OrderGetBindingModel model)
|
|
{
|
|
if (model.OrderNumber.IsNotEmpty())
|
|
{
|
|
return list.FirstOrDefault(x => x.OrderNumber == model.OrderNumber);
|
|
}
|
|
return base.GetSingleRecord(list, model);
|
|
}
|
|
}
|
|
} |