using CoreDatabase;
using CoreDatabase.Models.Department;
using DepartmentBusinessLogic.BindingModels;
using DepartmentBusinessLogic.Interfaces;
using DepartmentBusinessLogic.ViewModels;
using Microsoft.EntityFrameworkCore;
using ToolsModule.Enums;
using ToolsModule.Models;
using System.Linq;
namespace DepartmentDatabaseImplementation.Implementations
{
///
/// Реализация ILecturerAcademicRankService
///
public class LecturerAcademicRankService :
AbstractGenerticEntityService,
ILecturerAcademicRankService
{
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, LecturerAcademicRankSetBindingModel model) => OperationResultModel.Success(null);
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, LecturerAcademicRank entity, LecturerAcademicRankGetBindingModel model)
{
if (context.Set().Any(x => x.LecturerAcademicRankId == model.Id && !x.IsDeleted))
{
return OperationResultModel.Error("Error:", "Имеются сотрудники, использующую эту запись", ResultServiceStatusCode.ExsistItem);
}
return OperationResultModel.Success(null);
}
protected override IQueryable AdditionalCheckingWhenReadingList(IQueryable query, LecturerAcademicRankGetBindingModel model) => query;
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, LecturerAcademicRankSetBindingModel model) => OperationResultModel.Success(null);
protected override void AdditionalDeleting(DbContext context, LecturerAcademicRank entity, LecturerAcademicRankGetBindingModel model) { }
protected override LecturerAcademicRank GetUniqueEntity(LecturerAcademicRankSetBindingModel model, DbContext context) => context.Set().FirstOrDefault(x => x.LecturerAcademicRankName == model.LecturerAcademicRankName && x.Id != model.Id);
protected override IQueryable IncludingWhenReading(IQueryable query) => query;
protected override IQueryable OrderingWhenReading(IQueryable query) => query.OrderBy(x => x.Order);
}
}