DepartmentProject/DepartmentPortal/Department/DepartmentDatabaseImplementation.csproj/Implementations/AbstractGenerticEntityService/LecturerAcademicRankService.cs

42 lines
2.4 KiB
C#
Raw Normal View History

2022-03-18 22:55:48 +04:00
using CoreDatabase;
using CoreDatabase.Models.Department;
using DepartmentContract.BindingModels;
using DepartmentContract.Services.IGenericEntityService;
using DepartmentContract.ViewModels;
using Microsoft.EntityFrameworkCore;
using System.Linq;
2022-03-20 10:10:44 +04:00
using ToolsModule.ManagmentEntity;
namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService
{
/// <summary>
/// Реализация ILecturerAcademicRankService
/// </summary>
public class LecturerAcademicRankService :
AbstractGenerticEntityService<LecturerAcademicRankGetBindingModel, LecturerAcademicRankSetBindingModel, LecturerAcademicRank, LecturerAcademicRankListViewModel, LecturerAcademicRankViewModel>,
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<Lecturer>().Any(x => x.LecturerAcademicRankId == model.Id && !x.IsDeleted))
{
return OperationResultModel.Error("Error:", "Имеются сотрудники, использующую эту запись", ResultServiceStatusCode.ExsistItem);
}
return OperationResultModel.Success(null);
}
protected override IQueryable<LecturerAcademicRank> AdditionalCheckingWhenReadingList(IQueryable<LecturerAcademicRank> 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<LecturerAcademicRank> query) => query.FirstOrDefault(x => x.LecturerAcademicRankName == model.LecturerAcademicRankName && x.Id != model.Id);
protected override IQueryable<LecturerAcademicRank> IncludingWhenReading(IQueryable<LecturerAcademicRank> query) => query;
protected override IQueryable<LecturerAcademicRank> OrderingWhenReading(IQueryable<LecturerAcademicRank> query) => query.OrderBy(x => x.Order);
}
}