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
{
///
/// Реализация IPostService
///
public class PostService :
AbstractGenerticEntityService,
IPostService
{
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, PostSetBindingModel model) => OperationResultModel.Success(null);
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, Post entity, PostGetBindingModel model)
{
if (context.Set().Any(x => x.PostId == model.Id && !x.IsDeleted))
{
return OperationResultModel.Error("Error:", "Существуют сотрудники с этой должностью", ResultServiceStatusCode.ExsistItem);
}
if (context.Set().Any(x => x.PostId == model.Id && !x.IsDeleted))
{
return OperationResultModel.Error("Error:", "Существуют преподаватели с этой должностью", ResultServiceStatusCode.ExsistItem);
}
return OperationResultModel.Success(null);
}
protected override IQueryable AdditionalCheckingWhenReadingList(IQueryable query, PostGetBindingModel model) => query;
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, PostSetBindingModel model) => OperationResultModel.Success(null);
protected override void AdditionalDeleting(DbContext context, Post entity, PostGetBindingModel model) { }
protected override Post GetUniqueEntity(PostSetBindingModel model, DbContext context) => context.Set().FirstOrDefault(x => x.PostName == model.PostName && x.Id != model.Id);
protected override IQueryable IncludingWhenReading(IQueryable query) => query;
protected override IQueryable OrderingWhenReading(IQueryable query) => query.OrderByDescending(x => x.Order);
}
}