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
{
///
/// Реализация IStudentGroupService
///
public class StudentGroupService :
AbstractGenerticEntityService,
IStudentGroupService
{
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, StudentGroupSetBindingModel model) => OperationResultModel.Success(null);
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, StudentGroup entity, StudentGroupGetBindingModel model)
{
return OperationResultModel.Success(null);
}
protected override IQueryable AdditionalCheckingWhenReadingList(IQueryable query, StudentGroupGetBindingModel model)
{
if (model.AcademicPlanId.HasValue)
{
query = query.Where(x => x.AcademicPlanId == model.AcademicPlanId.Value);
}
if (model.LecturerId.HasValue)
{
query = query.Where(x => x.LecturerId == model.LecturerId.Value);
}
return query;
}
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, StudentGroupSetBindingModel model) => OperationResultModel.Success(null);
protected override void AdditionalDeleting(DbContext context, StudentGroup entity, StudentGroupGetBindingModel model) { }
protected override StudentGroup GetUniqueEntity(StudentGroupSetBindingModel model, DbContext context) => context.Set().FirstOrDefault(x => x.AcademicPlanId == model.AcademicPlanId && x.EnrollmentYear == model.EnrollmentYear && x.GroupNumber == model.GroupNumber && x.Id != model.Id);
protected override IQueryable IncludingWhenReading(IQueryable query) => query.Include(x => x.AcademicPlan).Include(x => x.Lecturer);
protected override IQueryable OrderingWhenReading(IQueryable query) => query.OrderBy(x => x.EnrollmentYear).ThenBy(x => x.GroupNumber);
}
}