2021-04-05 12:25:10 +04:00
|
|
|
|
using DatabaseCore;
|
|
|
|
|
using DatabaseCore.Models.Department;
|
|
|
|
|
using DepartmentBusinessLogic.BindingModels;
|
|
|
|
|
using DepartmentBusinessLogic.Interfaces;
|
|
|
|
|
using DepartmentBusinessLogic.ViewModels;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-03-18 22:38:52 +04:00
|
|
|
|
using ToolsModule.Enums;
|
|
|
|
|
using ToolsModule.Models;
|
2021-04-05 12:25:10 +04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace DepartmentDatabaseImplementation.Implementations
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2021-04-06 22:07:11 +04:00
|
|
|
|
/// Реализация IPostService
|
2021-04-05 12:25:10 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
public class PostService :
|
|
|
|
|
AbstractGenerticEntityService<PostGetBindingModel, PostSetBindingModel, Post, PostListViewModel, PostViewModel>,
|
|
|
|
|
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<EmployeePost>().Any(x => x.PostId == model.Id && !x.IsDeleted))
|
|
|
|
|
{
|
|
|
|
|
return OperationResultModel.Error("Error:", "Существуют сотрудники с этой должностью", ResultServiceStatusCode.ExsistItem);
|
|
|
|
|
}
|
|
|
|
|
if (context.Set<LecturerPost>().Any(x => x.PostId == model.Id && !x.IsDeleted))
|
|
|
|
|
{
|
|
|
|
|
return OperationResultModel.Error("Error:", "Существуют преподаватели с этой должностью", ResultServiceStatusCode.ExsistItem);
|
|
|
|
|
}
|
|
|
|
|
return OperationResultModel.Success(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IQueryable<Post> AdditionalCheckingWhenReadingList(IQueryable<Post> 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<Post>().FirstOrDefault(x => x.PostName == model.PostName && x.Id != model.Id);
|
|
|
|
|
|
|
|
|
|
protected override IQueryable<Post> IncludingWhenReading(IQueryable<Post> query) => query;
|
|
|
|
|
|
2021-04-05 14:20:07 +04:00
|
|
|
|
protected override IQueryable<Post> OrderingWhenReading(IQueryable<Post> query) => query.OrderByDescending(x => x.Order);
|
2021-04-05 12:25:10 +04:00
|
|
|
|
}
|
|
|
|
|
}
|