67 lines
3.2 KiB
C#
67 lines
3.2 KiB
C#
using CoreDatabase;
|
|
using CoreDatabase.Models.Department;
|
|
using DepartmentContract.BindingModels;
|
|
using DepartmentContract.Services.IGenericEntityService;
|
|
using DepartmentContract.ViewModels;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Linq;
|
|
using ToolsModule.ManagmentEntity;
|
|
|
|
namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService
|
|
{
|
|
/// <summary>
|
|
/// Реализация IStudentGroupService
|
|
/// </summary>
|
|
public class StudentGroupService :
|
|
AbstractGenerticEntityService<StudentGroupGetBindingModel, StudentGroupSetBindingModel, StudentGroup, StudentGroupListViewModel, StudentGroupViewModel>,
|
|
IStudentGroupService
|
|
{
|
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, StudentGroupSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, StudentGroup entity, StudentGroupGetBindingModel model)
|
|
{
|
|
if (context.Set<Student>().Any(x => x.StudentGroupId == model.Id && !x.IsDeleted))
|
|
{
|
|
return OperationResultModel.Error("Error:", "Есть студенты, относящиеся к этой группе", ResultServiceStatusCode.ExsistItem);
|
|
}
|
|
return OperationResultModel.Success(null);
|
|
}
|
|
|
|
protected override IQueryable<StudentGroup> AdditionalCheckingWhenReadingList(IQueryable<StudentGroup> query, StudentGroupGetBindingModel model)
|
|
{
|
|
if (model.EducationDirectionId.HasValue)
|
|
{
|
|
query = query.Where(x => x.AcademicPlan.EducationDirectionId == model.EducationDirectionId.Value);
|
|
}
|
|
if (model.AcademicPlanId.HasValue)
|
|
{
|
|
query = query.Where(x => x.AcademicPlanId == model.AcademicPlanId.Value);
|
|
}
|
|
if (model.LecturerId.HasValue)
|
|
{
|
|
query = query.Where(x => x.LecturerId == model.LecturerId.Value);
|
|
}
|
|
return query;
|
|
}
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, StudentGroupSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override void AdditionalDeleting(DbContext context, StudentGroup entity, StudentGroupGetBindingModel model)
|
|
{
|
|
var orders = context.Set<OrderStudentRecord>().Where(x => x.StudentGroupFromId == model.Id || x.StudentGroupToId == model.Id);
|
|
foreach (var o in orders)
|
|
{
|
|
o.IsDeleted = true;
|
|
o.DateDelete = DateTime.Now;
|
|
}
|
|
context.SaveChanges();
|
|
}
|
|
|
|
protected override StudentGroup GetUniqueEntity(StudentGroupSetBindingModel model, IQueryable<StudentGroup> query) => query.FirstOrDefault(x => x.AcademicPlanId == model.AcademicPlanId && x.YearEntrance == model.YearEntrance && x.GroupNumber == model.GroupNumber && x.Id != model.Id);
|
|
|
|
protected override IQueryable<StudentGroup> IncludingWhenReading(IQueryable<StudentGroup> query) => query.Include(x => x.AcademicPlan).Include(x => x.AcademicPlan.EducationDirection).Include(x => x.Lecturer).Include(x => x.Students);
|
|
|
|
protected override IQueryable<StudentGroup> OrderingWhenReading(IQueryable<StudentGroup> query) => query.OrderBy(x => x.AcademicPlan.EducationDirection.Qualification).ThenBy(x => x.AcademicPlan.EducationDirection.Cipher).ThenBy(x => x.YearEntrance).ThenBy(x => x.GroupNumber);
|
|
}
|
|
} |