50 lines
2.7 KiB
C#
50 lines
2.7 KiB
C#
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);
|
|
}
|
|
} |