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
{
///
/// Реализация IStudentAcademicProgress
///
public class StudentAcademicProgressService :
AbstractGenerticEntityService,
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 AdditionalCheckingWhenReadingList(IQueryable 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().FirstOrDefault(x => x.StudentId == model.StudentId && x.DisciplineId == model.DisciplineId && x.Semester == (int)model.Semester && x.Id != model.Id);
protected override IQueryable IncludingWhenReading(IQueryable query) => query.Include(x => x.Student).Include(x => x.Discipline);
protected override IQueryable OrderingWhenReading(IQueryable query) => query.OrderBy(x => x.Student.LastName).ThenBy(x => x.Student.FirstName);
}
}