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

68 lines
3.4 KiB
C#
Raw Normal View History

2021-04-13 12:52:45 +04:00
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>
/// Реализация IOrderStudentRecordService
/// </summary>
public class OrderStudentRecordService :
AbstractGenerticEntityService<OrderStudentRecordGetBindingModel, OrderStudentRecordSetBindingModel, OrderStudentRecord, OrderStudentRecordListViewModel, OrderStudentRecordViewModel>,
IOrderStudentRecordService
{
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, OrderStudentRecordSetBindingModel model) => OperationResultModel.Success(null);
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, OrderStudentRecord entity, OrderStudentRecordGetBindingModel model) => OperationResultModel.Success(null);
protected override IQueryable<OrderStudentRecord> AdditionalCheckingWhenReadingList(IQueryable<OrderStudentRecord> query, OrderStudentRecordGetBindingModel model)
{
if (model.OrderId.HasValue)
{
query = query.Where(x => x.OrderId == model.OrderId.Value);
}
if (model.StudentId.HasValue)
{
query = query.Where(x => x.StudentId == model.StudentId.Value);
}
if (model.StudentGroupId.HasValue)
{
query = query.Where(x => x.StudentGroupFromId == model.StudentGroupId.Value || x.StudentGroupToId == model.StudentGroupId.Value);
}
return query;
}
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, OrderStudentRecordSetBindingModel model) => OperationResultModel.Success(null);
protected override void AdditionalDeleting(DbContext context, OrderStudentRecord entity, OrderStudentRecordGetBindingModel model) { }
protected override OrderStudentRecord GetUniqueEntity(OrderStudentRecordSetBindingModel model, DbContext context) => context.Set<OrderStudentRecord>().FirstOrDefault(x => x.StudentId == model.StudentId && x.OrderId == model.OrderId && x.Id != model.Id);
protected override IQueryable<OrderStudentRecord> IncludingWhenReading(IQueryable<OrderStudentRecord> query) => query.Include(x => x.Order).Include(x => x.Student).Include(x => x.StudentGroupFrom).Include(x => x.StudentGroupTo);
protected override IQueryable<OrderStudentRecord> OrderingWhenReading(IQueryable<OrderStudentRecord> query) => query.OrderBy(x => x.Order.OrderDate).ThenBy(x => x.Order.OrderNumber).ThenBy(x => x.OrderStudentMoveType).ThenBy(x => x.Student.LastName).ThenBy(x => x.Student.FirstName);
protected override bool AdditionalCheckForSingleGet(OrderStudentRecordGetBindingModel model)
{
if (model.OrderId.HasValue && model.StudentId.HasValue && model.OrderStudentMoveType.HasValue)
{
return true;
}
return base.AdditionalCheckForSingleGet(model);
}
protected override OrderStudentRecord GetSingleRecord(IQueryable<OrderStudentRecord> list, OrderStudentRecordGetBindingModel model)
{
if (model.OrderId.HasValue && model.StudentId.HasValue && model.OrderStudentMoveType.HasValue)
{
return list.FirstOrDefault(x => x.OrderId == model.OrderId && x.StudentId == model.StudentId && x.OrderStudentMoveType == model.OrderStudentMoveType);
}
return base.GetSingleRecord(list, model);
}
2021-04-13 12:52:45 +04:00
}
}