DepartmentProject/DepartmentPortal/AcademicProgressDatabaseImplementation/Implementations/StudentAcademicProgressService.cs

53 lines
2.6 KiB
C#

using AcademicProgressBusinessLogic.BindingModels;
using AcademicProgressBusinessLogic.Interfaces;
using AcademicProgressBusinessLogic.ViewModels;
using DatabaseCore;
using DatabaseCore.Models.AcademicProgress;
using Microsoft.EntityFrameworkCore;
using ModuleTools.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AcademicProgressDatabaseImplementation.Implementations
{
/// <summary>
/// Реализация IStudentAcademicProgress
/// </summary>
public class StudentAcademicProgressService :
AbstractGenerticEntityService<StudentAcademicProgressGetBindingModel, StudentAcademicProgressSetBindingModel, StudentAcademicProgress, StudentAcademicProgressListViewModel, StudentAcademicProgressViewModels>,
IStudentAcademicProgressService
{
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, StudentAcademicProgressSetBindingModel model) => OperationResultModel.Success(null);
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, StudentAcademicProgress entity, StudentAcademicProgressGetBindingModel model) => OperationResultModel.Success(null);
protected override IQueryable<StudentAcademicProgress> AdditionalCheckingWhenReadingList(IQueryable<StudentAcademicProgress> query, StudentAcademicProgressGetBindingModel model)
{
if (model.StudentId.HasValue)
{
query = query.Where(x => x.StudentId == model.StudentId.Value);
}
if (model.DisciplineId.HasValue)
{
query = query.Where(x => x.DisciplineId == model.DisciplineId.Value);
}
return query;
}
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, StudentAcademicProgressSetBindingModel model) => OperationResultModel.Success(null);
protected override void AdditionalDeleting(DbContext context, StudentAcademicProgress entity, StudentAcademicProgressGetBindingModel model) { }
protected override StudentAcademicProgress GetUniqueEntity(StudentAcademicProgressSetBindingModel model, DbContext context) => context.Set<StudentAcademicProgress>().FirstOrDefault(x => x.StudentId == model.StudentId && x.DisciplineId == model.DisciplineId && x.Semester == (int)model.Semester && x.Id != model.Id);
protected override IQueryable<StudentAcademicProgress> IncludingWhenReading(IQueryable<StudentAcademicProgress> query) => query.Include(x => x.Student).Include(x => x.Discipline);
protected override IQueryable<StudentAcademicProgress> OrderingWhenReading(IQueryable<StudentAcademicProgress> query) => query.OrderBy(x => x.Student.LastName).ThenBy(x => x.Student.FirstName);
}
}