60 lines
2.6 KiB
C#
60 lines
2.6 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>
|
|
/// Реализация IAcademicPlanService
|
|
/// </summary>
|
|
public class AcademicPlanService :
|
|
AbstractGenerticEntityService<AcademicPlanGetBindingModel, AcademicPlanSetBindingModel, AcademicPlan, AcademicPlanListViewModel, AcademicPlanViewModel>,
|
|
IAcademicPlanService
|
|
{
|
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, AcademicPlanSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, AcademicPlan entity, AcademicPlanGetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override IQueryable<AcademicPlan> AdditionalCheckingWhenReadingList(IQueryable<AcademicPlan> query, AcademicPlanGetBindingModel model)
|
|
{
|
|
if (model.EducationDirectionId.HasValue)
|
|
{
|
|
query = query.Where(x => x.EducationDirectionId == model.EducationDirectionId.Value);
|
|
}
|
|
return query;
|
|
}
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, AcademicPlanSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override void AdditionalDeleting(DbContext context, AcademicPlan entity, AcademicPlanGetBindingModel model)
|
|
{
|
|
var records = context.Set<AcademicPlanRecord>().Where(x => x.AcademicPlanId == model.Id);
|
|
foreach (var record in records)
|
|
{
|
|
var hours = context.Set<AcademicPlanRecordTimeNormHour>().Where(x => x.AcademicPlanRecordId == record.Id);
|
|
foreach (var hour in hours)
|
|
{
|
|
hour.IsDeleted = true;
|
|
hour.DateDelete = DateTime.Now;
|
|
}
|
|
context.SaveChanges();
|
|
|
|
record.IsDeleted = true;
|
|
record.DateDelete = DateTime.Now;
|
|
}
|
|
context.SaveChanges();
|
|
}
|
|
|
|
protected override AcademicPlan GetUniqueEntity(AcademicPlanSetBindingModel model, DbContext context) => context.Set<AcademicPlan>().FirstOrDefault(x => x.EducationDirectionId == model.EducationDirectionId && x.YearEntrance == model.YearEntrance && x.Id != model.Id);
|
|
|
|
protected override IQueryable<AcademicPlan> IncludingWhenReading(IQueryable<AcademicPlan> query) => query.Include(x => x.EducationDirection);
|
|
|
|
protected override IQueryable<AcademicPlan> OrderingWhenReading(IQueryable<AcademicPlan> query) => query.OrderBy(x => x.EducationDirection.Cipher).ThenBy(x => x.YearEntrance);
|
|
}
|
|
} |