DepartmentProject/DepartmentPortal/Security/SecurityDatabaseImplementation/Implementations/EnviromentSettingService.cs

44 lines
2.1 KiB
C#

using DatabaseCore;
using DatabaseCore.Models.Security;
using Microsoft.EntityFrameworkCore;
using ModuleTools.Extensions;
using ModuleTools.Models;
using SecurityBusinessLogic.BindingModels;
using SecurityBusinessLogic.Interfaces;
using SecurityBusinessLogic.ViewModels;
using System.Linq;
namespace SecurityDatabaseImplementation.Implementations
{
/// <summary>
/// Реализация IEnviromentSettingService
/// </summary>
public class EnviromentSettingService :
AbstractGenerticEntityService<EnviromentSettingGetBindingModel, EnviromentSettingSetBindingModel, EnviromentSetting, EnviromentSettingListViewModel, EnviromentSettingViewModel>,
IEnviromentSettingService
{
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, EnviromentSettingSetBindingModel model) => OperationResultModel.Success(null);
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, EnviromentSetting entity, EnviromentSettingGetBindingModel model) => OperationResultModel.Success(null);
protected override IQueryable<EnviromentSetting> AdditionalCheckingWhenReadingList(IQueryable<EnviromentSetting> query, EnviromentSettingGetBindingModel model)
{
if(model.Key.IsNotEmpty())
{
query = query.Where(x => x.Key == model.Key);
}
return query;
}
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, EnviromentSettingSetBindingModel model) => OperationResultModel.Success(null);
protected override void AdditionalDeleting(DbContext context, EnviromentSetting entity, EnviromentSettingGetBindingModel model) { }
protected override EnviromentSetting GetUniqueEntity(EnviromentSettingSetBindingModel model, DbContext context) => context.Set<EnviromentSetting>().FirstOrDefault(x => x.Key == model.Key && x.Id != model.Id);
protected override IQueryable<EnviromentSetting> IncludingWhenReading(IQueryable<EnviromentSetting> query) => query;
protected override IQueryable<EnviromentSetting> OrderingWhenReading(IQueryable<EnviromentSetting> query) => query.OrderBy(x => x.Key);
}
}