2022-03-27 01:20:51 +04:00
|
|
|
|
using CoreDatabase;
|
|
|
|
|
using CoreDatabase.Models.Department;
|
|
|
|
|
using DepartmentContract.BindingModels;
|
|
|
|
|
using DepartmentContract.Services.IGenericEntityService;
|
|
|
|
|
using DepartmentContract.ViewModels;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using ToolsModule.ManagmentEntity;
|
|
|
|
|
|
|
|
|
|
namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Реализация IEnrollmentYearService
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class EnrollmentYearService :
|
|
|
|
|
AbstractGenerticEntityService<EnrollmentYearGetBindingModel, EnrollmentYearSetBindingModel, EnrollmentYear, EnrollmentYearListViewModel, EnrollmentYearViewModel>,
|
|
|
|
|
IEnrollmentYearService
|
|
|
|
|
{
|
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, EnrollmentYearSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
|
|
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, EnrollmentYear entity, EnrollmentYearGetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
|
|
|
|
|
|
protected override IQueryable<EnrollmentYear> AdditionalCheckingWhenReadingList(IQueryable<EnrollmentYear> query, EnrollmentYearGetBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model.AcademicPlanId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.AcademicPlanId == model.AcademicPlanId.Value);
|
|
|
|
|
}
|
2022-03-29 13:33:32 +04:00
|
|
|
|
if (model.EducationDirectionId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.AcademicPlan.EducationDirectionId == model.EducationDirectionId.Value);
|
|
|
|
|
}
|
|
|
|
|
if (model.Year.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.YearEntrance == model.Year.Value);
|
|
|
|
|
}
|
2022-03-27 01:20:51 +04:00
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, EnrollmentYearSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
|
|
|
|
|
|
protected override void AdditionalDeleting(DbContext context, EnrollmentYear entity, EnrollmentYearGetBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
var records = context.Set<Student>().Where(x => x.EnrollmentYearId == model.Id);
|
|
|
|
|
foreach (var record in records)
|
|
|
|
|
{
|
|
|
|
|
record.EnrollmentYearId = null;
|
|
|
|
|
}
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-29 13:33:32 +04:00
|
|
|
|
protected override EnrollmentYear GetUniqueEntity(EnrollmentYearSetBindingModel model, IQueryable<EnrollmentYear> query) => query.FirstOrDefault(x => x.AcademicPlanId == model.AcademicPlanId && x.YearEntrance == model.YearEntrance && x.Id != model.Id);
|
2022-03-27 01:20:51 +04:00
|
|
|
|
|
|
|
|
|
protected override IQueryable<EnrollmentYear> IncludingWhenReading(IQueryable<EnrollmentYear> query) => query.Include(x => x.AcademicPlan).Include(x => x.AcademicPlan.EducationDirection);
|
|
|
|
|
|
|
|
|
|
protected override IQueryable<EnrollmentYear> OrderingWhenReading(IQueryable<EnrollmentYear> query) => query.OrderBy(x => x.AcademicPlan.EducationDirection.Cipher).ThenBy(x => x.YearEntrance);
|
2022-03-29 13:33:32 +04:00
|
|
|
|
|
|
|
|
|
protected override bool AdditionalCheckForSingleGet(EnrollmentYearGetBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model.EducationDirectionId.HasValue && model.Year.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return base.AdditionalCheckForSingleGet(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override EnrollmentYear GetSingleRecord(IQueryable<EnrollmentYear> list, EnrollmentYearGetBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model.EducationDirectionId.HasValue && model.Year.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return list.FirstOrDefault(x => x.AcademicPlan.EducationDirectionId == model.EducationDirectionId && x.YearEntrance == model.Year);
|
|
|
|
|
}
|
|
|
|
|
return base.GetSingleRecord(list, model);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-27 01:20:51 +04:00
|
|
|
|
}
|