using CoreDatabase;
using CoreDatabase.Models.Department;
using DepartmentContract.BindingModels;
using DepartmentContract.Services.IGenericEntityService;
using DepartmentContract.ViewModels;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using ToolsModule.ManagmentEntity;
namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService
{
///
/// Реализация 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, IQueryable query) => query.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);
}
}