2022-03-18 22:55:48 +04:00
|
|
|
|
using CoreDatabase;
|
|
|
|
|
using CoreDatabase.Models.Department;
|
2022-03-19 22:48:13 +04:00
|
|
|
|
using DepartmentContract.BindingModels;
|
|
|
|
|
using DepartmentContract.Services.IGenericEntityService;
|
|
|
|
|
using DepartmentContract.ViewModels;
|
2021-04-12 10:01:42 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2021-04-13 12:52:45 +04:00
|
|
|
|
using System;
|
2021-04-12 10:01:42 +04:00
|
|
|
|
using System.Linq;
|
2022-03-20 10:10:44 +04:00
|
|
|
|
using ToolsModule.ManagmentEntity;
|
2021-04-12 10:01:42 +04:00
|
|
|
|
|
2022-03-19 22:48:13 +04:00
|
|
|
|
namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService
|
2021-04-12 10:01:42 +04:00
|
|
|
|
{
|
2022-03-19 22:48:13 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Реализация IStudentGroupService
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class StudentGroupService :
|
2021-04-12 10:01:42 +04:00
|
|
|
|
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)
|
|
|
|
|
{
|
2021-04-12 16:57:29 +04:00
|
|
|
|
if (context.Set<Student>().Any(x => x.StudentGroupId == model.Id && !x.IsDeleted))
|
|
|
|
|
{
|
|
|
|
|
return OperationResultModel.Error("Error:", "Есть студенты, относящиеся к этой группе", ResultServiceStatusCode.ExsistItem);
|
|
|
|
|
}
|
2021-04-12 10:01:42 +04:00
|
|
|
|
return OperationResultModel.Success(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IQueryable<StudentGroup> AdditionalCheckingWhenReadingList(IQueryable<StudentGroup> query, StudentGroupGetBindingModel model)
|
|
|
|
|
{
|
2021-04-27 18:04:01 +04:00
|
|
|
|
if (model.EducationDirectionId.HasValue)
|
2021-04-12 10:01:42 +04:00
|
|
|
|
{
|
2021-04-27 18:04:01 +04:00
|
|
|
|
query = query.Where(x => x.EducationDirectionId == model.EducationDirectionId.Value);
|
2021-04-12 10:01:42 +04:00
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
2021-04-13 12:52:45 +04:00
|
|
|
|
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();
|
|
|
|
|
}
|
2021-04-12 10:01:42 +04:00
|
|
|
|
|
2022-03-29 13:33:32 +04:00
|
|
|
|
protected override StudentGroup GetUniqueEntity(StudentGroupSetBindingModel model, IQueryable<StudentGroup> query) => query.FirstOrDefault(x => x.EducationDirectionId == model.EducationDirectionId && x.AcademicCourse == model.AcademicCourse && x.GroupNumber == model.GroupNumber && x.Id != model.Id);
|
2021-04-12 10:01:42 +04:00
|
|
|
|
|
2021-08-20 18:28:34 +04:00
|
|
|
|
protected override IQueryable<StudentGroup> IncludingWhenReading(IQueryable<StudentGroup> query) => query.Include(x => x.EducationDirection).Include(x => x.Lecturer).Include(x => x.Students);
|
2021-04-12 10:01:42 +04:00
|
|
|
|
|
2021-04-27 18:04:01 +04:00
|
|
|
|
protected override IQueryable<StudentGroup> OrderingWhenReading(IQueryable<StudentGroup> query) => query.OrderBy(x => x.EducationDirection.Cipher).ThenBy(x => x.AcademicCourse).ThenBy(x => x.GroupNumber);
|
2021-04-12 10:01:42 +04:00
|
|
|
|
}
|
|
|
|
|
}
|