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 16:57:29 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2021-04-13 12:52:45 +04:00
|
|
|
|
using System;
|
2021-04-12 16:57:29 +04:00
|
|
|
|
using System.Linq;
|
2022-03-20 10:10:44 +04:00
|
|
|
|
using ToolsModule.ManagmentEntity;
|
|
|
|
|
using ToolsModule.ManagmentExtension;
|
2021-04-12 16:57:29 +04:00
|
|
|
|
|
2022-03-19 22:48:13 +04:00
|
|
|
|
namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService
|
2021-04-12 16:57:29 +04:00
|
|
|
|
{
|
2022-03-19 22:48:13 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Реализация IStudentService
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class StudentService :
|
2021-04-12 16:57:29 +04:00
|
|
|
|
AbstractGenerticEntityService<StudentGetBindingModel, StudentSetBindingModel, Student, StudentListViewModel, StudentViewModel>,
|
|
|
|
|
IStudentService
|
|
|
|
|
{
|
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, StudentSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
|
|
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, Student entity, StudentGetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
|
|
|
|
|
|
protected override IQueryable<Student> AdditionalCheckingWhenReadingList(IQueryable<Student> query, StudentGetBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model.UserId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.UserId == model.UserId.Value);
|
|
|
|
|
}
|
|
|
|
|
if (model.StudentGroupId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.StudentGroupId == model.StudentGroupId.Value);
|
|
|
|
|
}
|
2022-03-27 01:20:51 +04:00
|
|
|
|
if (model.EnrollmentYearId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.EnrollmentYearId == model.EnrollmentYearId.Value);
|
|
|
|
|
}
|
2021-04-12 16:57:29 +04:00
|
|
|
|
if (model.StudentState.HasValue)
|
|
|
|
|
{
|
2022-03-18 22:08:29 +04:00
|
|
|
|
query = query.Where(x => x.StudentState == model.StudentState.Value);
|
2021-04-12 16:57:29 +04:00
|
|
|
|
}
|
2022-03-27 14:51:27 +04:00
|
|
|
|
if (model.BasicDepartmentId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.BasicDepartmentId == model.BasicDepartmentId.Value);
|
|
|
|
|
}
|
2021-04-12 16:57:29 +04:00
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, StudentSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
|
|
2021-04-13 12:52:45 +04:00
|
|
|
|
protected override void AdditionalDeleting(DbContext context, Student entity, StudentGetBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
var orders = context.Set<OrderStudentRecord>().Where(x => x.StudentId == model.Id);
|
|
|
|
|
foreach (var o in orders)
|
|
|
|
|
{
|
|
|
|
|
o.IsDeleted = true;
|
|
|
|
|
o.DateDelete = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
}
|
2021-04-12 16:57:29 +04:00
|
|
|
|
|
2022-03-29 13:33:32 +04:00
|
|
|
|
protected override Student GetUniqueEntity(StudentSetBindingModel model, IQueryable<Student> query) => query.FirstOrDefault(x => x.NumberOfBook == model.NumberOfBook && x.Id != model.Id);
|
2021-04-12 16:57:29 +04:00
|
|
|
|
|
|
|
|
|
protected override IQueryable<Student> IncludingWhenReading(IQueryable<Student> query) => query.Include(x => x.StudentGroup).Include(x => x.User);
|
|
|
|
|
|
2021-04-27 18:04:01 +04:00
|
|
|
|
protected override IQueryable<Student> OrderingWhenReading(IQueryable<Student> query) => query.OrderBy(x => x.StudentGroup.AcademicCourse).ThenBy(x => x.StudentGroup.GroupNumber).ThenBy(x => x.LastName).ThenBy(x => x.FirstName);
|
2021-04-28 17:58:52 +04:00
|
|
|
|
|
|
|
|
|
protected override bool AdditionalCheckForSingleGet(StudentGetBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model.NumberOfBook.IsNotEmpty())
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return base.AdditionalCheckForSingleGet(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Student GetSingleRecord(IQueryable<Student> list, StudentGetBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model.NumberOfBook.IsNotEmpty())
|
|
|
|
|
{
|
|
|
|
|
return list.FirstOrDefault(x => x.NumberOfBook == model.NumberOfBook);
|
|
|
|
|
}
|
|
|
|
|
return base.GetSingleRecord(list, model);
|
|
|
|
|
}
|
2021-04-12 16:57:29 +04:00
|
|
|
|
}
|
|
|
|
|
}
|