using CoreDatabase;
using CoreDatabase.Models.Department;
using DepartmentContract.BindingModels;
using DepartmentContract.Services.IGenericEntityService;
using DepartmentContract.ViewModels;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using ToolsModule.Models;
namespace DepartmentDatabaseImplementation.Implementations.AbstractGenerticEntityService
{
///
/// Реализация IEmployeePostService
///
public class EmployeePostService :
AbstractGenerticEntityService,
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 AdditionalCheckingWhenReadingList(IQueryable 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().FirstOrDefault(x => x.EmployeeId == model.EmployeeId && x.PostId == model.PostId && x.Id != model.Id);
protected override IQueryable IncludingWhenReading(IQueryable query) => query.Include(x => x.Post).Include(x => x.Employee);
protected override IQueryable OrderingWhenReading(IQueryable query) => query.OrderBy(x => x.Employee.LastName);
}
}