DepartmentProject/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/Implementations/AbstractGenerticEntityService/StudentMarkPassedDisciplineService.cs

63 lines
3.5 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>
/// Реализация IStudentMarkPassedDisciplineService
/// </summary>
public class StudentMarkPassedDisciplineService :
AbstractGenerticEntityService<StudentMarkPassedDisciplineGetBindingModel, StudentMarkPassedDisciplineSetBindingModel, StudentMarkPassedDiscipline, StudentMarkPassedDisciplineListViewModel, StudentMarkPassedDisciplineViewModel>,
IStudentMarkPassedDisciplineService
{
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, StudentMarkPassedDisciplineSetBindingModel model) => OperationResultModel.Success(null);
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, StudentMarkPassedDiscipline entity, StudentMarkPassedDisciplineGetBindingModel model) => OperationResultModel.Success(null);
protected override IQueryable<StudentMarkPassedDiscipline> AdditionalCheckingWhenReadingList(IQueryable<StudentMarkPassedDiscipline> query, StudentMarkPassedDisciplineGetBindingModel model)
{
if (model.DisciplineId.HasValue)
{
query = query.Where(x => x.DisciplineId == model.DisciplineId);
}
if (model.StudentId.HasValue)
{
query = query.Where(x => x.StudentId == model.StudentId);
}
if (model.StudentGroupId.HasValue)
{
query = query.Where(x => x.Student.StudentGroupId == model.StudentGroupId);
}
if (model.DateStart.HasValue && model.DateFinish.HasValue)
{
query = query.Where(x => x.DateAffixing >= model.DateStart.Value && x.DateAffixing <= model.DateFinish.Value);
}
return query;
}
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, StudentMarkPassedDisciplineSetBindingModel model) => OperationResultModel.Success(null);
protected override void AdditionalDeleting(DbContext context, StudentMarkPassedDiscipline entity, StudentMarkPassedDisciplineGetBindingModel model)
{
throw new NotImplementedException();
}
protected override StudentMarkPassedDiscipline GetUniqueEntity(StudentMarkPassedDisciplineSetBindingModel model, IQueryable<StudentMarkPassedDiscipline> query) => query.FirstOrDefault(x => x.StudentId == model.StudentId && x.DisciplineId == model.DisciplineId &&
x.Semester == model.Semester && x.Mark == model.Mark && x.Id != model.Id);
protected override IQueryable<StudentMarkPassedDiscipline> IncludingWhenReading(IQueryable<StudentMarkPassedDiscipline> query) => query
.Include(x => x.Student)
.Include(x => x.Discipline);
protected override IQueryable<StudentMarkPassedDiscipline> OrderingWhenReading(IQueryable<StudentMarkPassedDiscipline> query) => query
.OrderByDescending(x => x.Student)
.ThenBy(x => x.DateAffixing);
}
}