50 lines
2.2 KiB
C#
50 lines
2.2 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.Linq;
|
|||
|
|
|||
|
namespace DepartmentDatabaseImplementation.Implementations
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Реализация IStudentService
|
|||
|
/// </summary>
|
|||
|
public class StudentService :
|
|||
|
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);
|
|||
|
}
|
|||
|
if (model.StudentState.HasValue)
|
|||
|
{
|
|||
|
query = query.Where(x => x.StudentState == (int)model.StudentState.Value);
|
|||
|
}
|
|||
|
return query;
|
|||
|
}
|
|||
|
|
|||
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, StudentSetBindingModel model) => OperationResultModel.Success(null);
|
|||
|
|
|||
|
protected override void AdditionalDeleting(DbContext context, Student entity, StudentGetBindingModel model) { }
|
|||
|
|
|||
|
protected override Student GetUniqueEntity(StudentSetBindingModel model, DbContext context) => context.Set<Student>().FirstOrDefault(x => x.NumberOfBook == model.NumberOfBook && x.Id != model.Id);
|
|||
|
|
|||
|
protected override IQueryable<Student> IncludingWhenReading(IQueryable<Student> query) => query.Include(x => x.StudentGroup).Include(x => x.User);
|
|||
|
|
|||
|
protected override IQueryable<Student> OrderingWhenReading(IQueryable<Student> query) => query.OrderBy(x => x.StudentGroup.EnrollmentYear).ThenBy(x => x.StudentGroup.GroupNumber).ThenBy(x => x.LastName).ThenBy(x => x.FirstName);
|
|||
|
}
|
|||
|
}
|