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

43 lines
2.4 KiB
C#

using DatabaseCore;
using DatabaseCore.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
{
/// <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, DbContext context) => context.Set<LecturerAcademicRank>().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);
}
}