46 lines
2.2 KiB
C#
46 lines
2.2 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// Реализация IEmployeePostService
|
|
/// </summary>
|
|
public class EmployeePostService :
|
|
AbstractGenerticEntityService<EmployeePostGetBindingModel, EmployeePostSetBindingModel, EmployeePost, EmployeePostListViewModel, EmployeePostViewModel>,
|
|
IEmployeePostService
|
|
{
|
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, EmployeePostSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, EmployeePost entity, EmployeePostGetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override IQueryable<EmployeePost> AdditionalCheckingWhenReadingList(IQueryable<EmployeePost> query, EmployeePostGetBindingModel model)
|
|
{
|
|
if (model.PostId.HasValue)
|
|
{
|
|
query = query.Where(x => x.PostId == model.PostId);
|
|
}
|
|
if (model.EmployeeId.HasValue)
|
|
{
|
|
query = query.Where(x => x.EmployeeId == model.EmployeeId);
|
|
}
|
|
return query;
|
|
}
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, EmployeePostSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override void AdditionalDeleting(DbContext context, EmployeePost entity, EmployeePostGetBindingModel model) { }
|
|
|
|
protected override EmployeePost GetUniqueEntity(EmployeePostSetBindingModel model, DbContext context) => context.Set<EmployeePost>().FirstOrDefault(x => x.EmployeeId == model.EmployeeId && x.PostId == model.PostId && x.Id != model.Id);
|
|
|
|
protected override IQueryable<EmployeePost> IncludingWhenReading(IQueryable<EmployeePost> query) => query.Include(x => x.Post).Include(x => x.Employee);
|
|
|
|
protected override IQueryable<EmployeePost> OrderingWhenReading(IQueryable<EmployeePost> query) => query.OrderBy(x => x.Employee.LastName);
|
|
}
|
|
} |