61 lines
2.9 KiB
C#
61 lines
2.9 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;
|
|
using System.Linq;
|
|
|
|
namespace DepartmentDatabaseImplementation.Implementations
|
|
{
|
|
/// <summary>
|
|
/// Реализация IAcademicPlanRecordService
|
|
/// </summary>
|
|
public class AcademicPlanRecordService :
|
|
AbstractGenerticEntityService<AcademicPlanRecordGetBindingModel, AcademicPlanRecordSetBindingModel, AcademicPlanRecord, AcademicPlanRecordListViewModel, AcademicPlanRecordViewModel>,
|
|
IAcademicPlanRecordService
|
|
{
|
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, AcademicPlanRecordSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, AcademicPlanRecord entity, AcademicPlanRecordGetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override IQueryable<AcademicPlanRecord> AdditionalCheckingWhenReadingList(IQueryable<AcademicPlanRecord> query, AcademicPlanRecordGetBindingModel model)
|
|
{
|
|
if (model.AcademicPlanId.HasValue)
|
|
{
|
|
query = query.Where(x => x.AcademicPlanId == model.AcademicPlanId.Value);
|
|
}
|
|
if (model.DisciplineId.HasValue)
|
|
{
|
|
query = query.Where(x => x.DisciplineId == model.DisciplineId.Value);
|
|
}
|
|
if (model.Semester.HasValue)
|
|
{
|
|
query = query.Where(x => x.Semester == model.Semester.Value);
|
|
}
|
|
return query;
|
|
}
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, AcademicPlanRecordSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override void AdditionalDeleting(DbContext context, AcademicPlanRecord entity, AcademicPlanRecordGetBindingModel model)
|
|
{
|
|
var hours = context.Set<AcademicPlanRecordTimeNormHour>().Where(x => x.AcademicPlanRecordId == model.Id);
|
|
foreach (var hour in hours)
|
|
{
|
|
hour.IsDeleted = true;
|
|
hour.DateDelete = DateTime.Now;
|
|
}
|
|
context.SaveChanges();
|
|
}
|
|
|
|
protected override AcademicPlanRecord GetUniqueEntity(AcademicPlanRecordSetBindingModel model, DbContext context) => context.Set<AcademicPlanRecord>().FirstOrDefault(x => x.AcademicPlanId == model.AcademicPlanId && x.DisciplineId == model.DisciplineId && x.Semester == model.Semester && x.Id != model.Id);
|
|
|
|
protected override IQueryable<AcademicPlanRecord> IncludingWhenReading(IQueryable<AcademicPlanRecord> query) => query.Include(x => x.AcademicPlan).Include(x => x.Discipline);
|
|
|
|
protected override IQueryable<AcademicPlanRecord> OrderingWhenReading(IQueryable<AcademicPlanRecord> query) =>
|
|
query.OrderBy(x => x.AcademicPlanId).ThenBy(x => x.Semester).ThenBy(x => x.AcademicPlanRecordParentId.HasValue || x.IsParent).ThenBy(x => x.AcademicPlanRecordParentId.HasValue).ThenBy(x => x.Discipline.DisciplineName);
|
|
}
|
|
} |