feat: разделение на repository - services

This commit is contained in:
Mikhail Trubnikov
2026-04-14 09:56:31 +10:00
parent da83aff19c
commit 734c2e3c99
71 changed files with 333 additions and 605 deletions

View File

@@ -1,389 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.DomainModels;
using PARR.DAL.Services.Interfaces.Base;
using PARR.Domain.Entities.Base;
using PARR.Domain.Entities.Base.History;
using PARR.Domain.Entities.Base.History.Base;
using System.Reflection;
namespace PARR.DAL.Services.Abstracts
{
internal abstract class BaseService<T> : IBaseService<T> where T : class, IBaseEntity
{
private readonly ILogger<BaseService<T>> logger;
protected abstract DbSet<T> EntitySet { get; }
protected abstract DataContext EntitiContext { get; }
public BaseService(ILogger<BaseService<T>> logger)
{
this.logger = logger;
}
public virtual async Task<bool> AddRangeAsync(List<T> objs)
{
logger.LogDebug("Начинаю добавление диапазона объектов типа {EntityType}, количество: {Count}",
typeof(T).Name, objs.Count);
objs.ForEach(item => item.DateCreated = DateTimeOffset.UtcNow);
try
{
await EntitySet.AddRangeAsync(objs);
logger.LogDebug("Успешно добавлено {Count} объектов типа {EntityType}",
objs.Count, typeof(T).Name);
return true;
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка при добавлении диапазона объектов типа {EntityType}", typeof(T).Name);
return false;
}
}
public async Task<bool> CommitAsync(IHistoryInitiator? initiator = null)
{
logger.LogDebug("Начинаю сохранение изменений в БД для объектов типа {EntityType}", typeof(T).Name);
#region Изменения
var modifiedEntrities = EntitiContext.ChangeTracker.Entries()
.Where(t => t.State == EntityState.Modified/* || t.State == EntityState.Deleted*/);
logger.LogDebug("Найдено {Count} измененных сущностей для обработки истории", modifiedEntrities.Count());
foreach (var obj in modifiedEntrities)
{
// Если нужно, обновляем дату изменения
DateModifiedResolver(obj);
//Если нужно, пишем историю
TableHistoryResolver(obj);
}
#endregion
SetInitiator(initiator);
try
{
var changedCount = await EntitiContext.SaveChangesAsync();
logger.LogDebug("Успешно сохранено {ChangedCount} изменений в БД для объектов типа {EntityType}",
changedCount, typeof(T).Name);
return true;
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка при сохранении изменений в БД для объектов типа {EntityType}", typeof(T).Name);
return false;
}
}
/// <summary>
/// Установить инициатора
/// </summary>
/// <param name="initiator"></param>
private void SetInitiator(IHistoryInitiator? initiator)
{
logger.LogDebug("Устанавливаю инициатора для изменений");
// Задаем инициатора только для новых и измененных записей
var entrities = EntitiContext.ChangeTracker.Entries()
.Where(t => t.State == EntityState.Modified || t.State == EntityState.Added);
var entityCount = entrities.Count();
logger.LogDebug("Найдено {Count} сущностей для установки инициатора", entityCount);
// смотрим есть ли у объекта интерфейс IHistoryInitiator, если есть, задаём значения
foreach (var obj in entrities)
{
// для всех объектов которые наследуются от IHistoryInitiator и не являются наследниками IHistoryTable
if (obj.Entity is IHistoryInitiator && obj.Entity is IHistoryTable == false)
{
(obj.Entity as IHistoryInitiator)!.InitiatorIp = initiator?.InitiatorIp ?? null;
(obj.Entity as IHistoryInitiator)!.InitiatorParrComponentId = initiator?.InitiatorParrComponentId ?? null;
(obj.Entity as IHistoryInitiator)!.InitiatorComment = initiator?.InitiatorComment ?? null;
logger.LogDebug("Установлен инициатор для сущности типа {EntityType}", obj.Entity.GetType().Name);
}
}
}
/// <summary>
/// Обновления DateModified у таблиц с IBase
/// </summary>
/// <param name="obj"></param>
private void DateModifiedResolver(EntityEntry obj)
{
if (obj.Entity is IBaseEntityDateModified)
{
logger.LogDebug("Обновляю DateModified для сущности типа {EntityType}", obj.Entity.GetType().Name);
(obj.Entity as IBaseEntityDateModified)!.DateModified = DateTimeOffset.UtcNow;
}
}
/// <summary>
/// При необходимости, записывать историю таблиц
/// </summary>
/// <param name="obj"></param>
private void TableHistoryResolver(EntityEntry obj)
{
logger.LogDebug("Проверяю необходимость создания истории для сущности типа {EntityType}", obj.Entity.GetType().Name);
var myHistoryInterface = obj.Entity.GetType().GetInterfaces()
.Where(t => t.IsGenericType)
.Where(t => t.GetGenericTypeDefinition() == typeof(IMyHistory<>))
.FirstOrDefault();
// у этого объекта нет интерфейса IMyHistory<>. Не ведем историю
if (myHistoryInterface == null)
{
logger.LogDebug("Сущность типа {EntityType} не требует ведения истории", obj.Entity.GetType().Name);
return;
}
// !!! Эта таблица хочет хранить историю !!!
// Получаем тип таблицы где хранится история
var historyType = myHistoryInterface.GetGenericArguments().First();
var historyProps = historyType.GetProperties(/*BindingFlags.DeclaredOnly | */ /*BindingFlags.Public*/).ToList();
logger.LogDebug("Создаю историю для сущности типа {EntityType}, тип истории: {HistoryType}",
obj.Entity.GetType().Name, historyType.Name);
var historyInstance = Activator.CreateInstance(historyType);
if (historyInstance == null)
{
logger.LogError("Не смог создать инстанс для ведения истории {HistoryType}", historyType.Name);
return;
}
// Заполняем поля истории, полями которые есть в исходной таблице
FillHistoryProps(obj, ref historyInstance, historyProps);
// Заполняем поля интерфейса IHistoryTable
FillHistoryProp(ref historyInstance, nameof(IHistoryTable.DateAddedToHistory), DateTimeOffset.UtcNow);
// Заполняем Id
FillHistoryProp(ref historyInstance, nameof(IBaseEntity.Id), Guid.NewGuid());
try
{
EntitiContext.Add(historyInstance);
logger.LogDebug("История добавлена для сущности типа {EntityType}", obj.Entity.GetType().Name);
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка при добавлении объекта в историю {HistoryType}", historyType.Name);
}
}
/// <summary>
/// Заполнить объект истории
/// </summary>
/// <param name="originalObj"></param>
/// <param name="historyInstance"></param>
/// <param name="propsList"></param>
private void FillHistoryProps(EntityEntry originalObj, ref object historyInstance, List<PropertyInfo> propsList)
{
logger.LogDebug("Заполняю историю для сущности типа {EntityType}", originalObj.Entity.GetType().Name);
foreach (var prop in propsList)
{
if (originalObj.OriginalValues.Properties.FirstOrDefault(t => t.Name == prop.Name) == null)
continue;
var sourceObjProp = originalObj.Property(prop.Name);
if (sourceObjProp == null)
return;
//Смотрим, если это Id, записываем его в ParentId
var histPropName = prop.Name == nameof(IBaseEntity.Id) ? nameof(IHistoryTable.ParentId) : prop.Name;
var histProp = historyInstance.GetType().GetProperty(histPropName);
if (histProp == null) continue;
//сравним типы
if (sourceObjProp.Metadata.PropertyInfo?.PropertyType != histProp.PropertyType)
continue;
var origValues = originalObj.Property(prop.Name).OriginalValue;
histProp.SetValue(historyInstance, origValues);
}
logger.LogDebug("Завершено заполнение истории для сущности типа {EntityType}", originalObj.Entity.GetType().Name);
}
/// <summary>
/// Заполнить поле объекта
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="instanceObj"></param>
/// <param name="propName"></param>
/// <param name="value"></param>
private void FillHistoryProp<TValue>(ref object instanceObj, string propName, TValue value)
{
var histProp = instanceObj.GetType().GetProperty(propName);
if (histProp == null)
{
logger.LogError("При изменении объекта для БД, не найдено свойство {PropertyName}", propName);
return;
}
// сравним типы
if (histProp.PropertyType != typeof(TValue))
{
logger.LogError("При изменении объекта для БД, не совпадают типы у свойства {PropertyName}, {PropertyType}!={ValueType}",
propName, histProp.PropertyType.Name, typeof(TValue).Name);
return;
}
histProp.SetValue(instanceObj, value);
}
#region test, comments
//private void SaveHistory(EntityEntry obj)
//{
// // пока просто попробуем для шаблонов
// if (obj.Entity is Template == false)
// return;
// var template = (Template)obj.Entity;
// // https://stackoverflow.com/questions/15012621/how-to-get-original-entity-from-changetracker
// var history = new TemplateHistory();
// // {
// history.Id = Guid.NewGuid();
// history.ParentId = template.Id;
// history.DateAddedToHistory = DateTimeOffset.UtcNow;
// history.InitiatorIp = null;
// history.InitiatorParrComponentId = null;
// history.InitiatorComment = null;
// //---
// //DateModified="",
// //Name ="",
// //IsActiveTemplate = null,
// //IsActiveSchedule = null,
// //LastRun = null,
// //NextRun = null
// // DateModified = template.DateModified,
// // Name = template.Name,
// // IsActiveTemplate = template.IsActiveTemplate,
// // IsActiveSchedule = template.IsActiveSchedule,
// // LastRun = template.LastRun,
// // NextRun = template.NextRun
// //};
// // obj.OriginalValues.GetValue
// //ITemplateBase хочу получить все поля из интерфейса, потом заполнить по ним в хистори
// var interfaceType = typeof(ITemplateGeneralProps);
// foreach (var prop in interfaceType.GetProperties())
// {
// var propName = prop.Name;
// //var propType = prop.PropertyType;
// var originalPropValue = obj.OriginalValues.GetValue<object>(propName);
// var histProp = history.GetType().GetProperty(propName);
// histProp.SetValue(histProp, originalPropValue);
// }
// EntitiContext.Add(history);
//}
#endregion
public virtual async Task<bool> CreateAsync(T obj)
{
logger.LogDebug("Начинаю создание объекта типа {EntityType}", typeof(T).Name);
obj.DateCreated = DateTimeOffset.UtcNow;
try
{
await EntitySet.AddAsync(obj);
logger.LogDebug("Объект типа {EntityType} добавлен в контекст", typeof(T).Name);
return true;
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка при добавлении объекта типа {EntityType} в БД", typeof(T).Name);
return false;
}
}
public virtual bool Delete(T obj)
{
logger.LogDebug("Начинаю удаление объекта типа {EntityType}", obj.GetType().Name);
try
{
EntitySet.Remove(obj);
logger.LogDebug("Объект типа {EntityType} удален из контекста", obj.GetType().Name);
return true;
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка при удалении объекта типа {EntityType} из БД", obj.GetType().Name);
return false;
}
}
public virtual async Task<bool> DeleteAsync(Guid id)
{
logger.LogDebug("Начинаю удаление объекта типа {EntityType} по ID: {Id}", typeof(T).Name, id);
try
{
var exist = await GetAsync(id);
if (exist == null)
{
logger.LogError("Ошибка при удалении из БД. Не найдена запись в БД типа {EntityType} с id: {Id}",
typeof(T).Name, id);
return false;
}
EntitySet.Remove(exist);
logger.LogDebug("Объект типа {EntityType} с ID {Id} удален из контекста", typeof(T).Name, id);
return true;
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка при удалении объекта типа {EntityType} из БД по ID: {Id}", typeof(T).Name, id);
return false;
}
}
public virtual IQueryable<T> Get()
{
logger.LogDebug("Получаю набор объектов типа {EntityType}", typeof(T).Name);
return EntitySet;
}
public virtual async Task<T?> GetAsync(Guid id)
{
logger.LogDebug("Получаю объект типа {EntityType} по ID: {Id}", typeof(T).Name, id);
return await EntitySet.FirstOrDefaultAsync(t => t.Id == id);
}
public virtual IQueryable<T> GetPage(IQueryable<T> query, PaginationFilter paginationFilter)
{
logger.LogDebug("Получаю страницу объектов типа {EntityType}, страница: {PageNumber}, размер: {PageSize}",
typeof(T).Name, paginationFilter.PageNumber, paginationFilter.PageSize);
int skip = (paginationFilter.PageNumber - 1) * paginationFilter.PageSize;
return query.Skip(skip).Take(paginationFilter.PageSize);
}
}
}

View File

@@ -1,23 +1,14 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class AgentHistoryService : BaseService<AgentHistory>, IAgentHistoryService
internal class AgentHistoryService : BaseRepository<AgentHistory>, IAgentHistoryService
{
private readonly DataContext dataContext;
public AgentHistoryService(DataContext dataContext, ILogger<AgentHistoryService> logger) : base(logger, dataContext) { }
public AgentHistoryService(DataContext dataContext, ILogger<AgentHistoryService> logger) : base(logger)
{
this.dataContext = dataContext;
}
protected override DbSet<AgentHistory> EntitySet => dataContext.AgentHistories;
protected override DataContext EntitiContext => dataContext;
}
}

View File

@@ -1,25 +1,14 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class ApplicationInHostService : BaseService<ApplicationInHost>, IApplicationInHostService
internal class ApplicationInHostService : BaseRepository<ApplicationInHost>, IApplicationInHostService
{
private readonly DataContext dataContext;
private readonly ILogger<ApplicationInHostService> logger;
public ApplicationInHostService(DataContext dataContext, ILogger<ApplicationInHostService> logger) : base(logger, dataContext) { }
public ApplicationInHostService(DataContext dataContext, ILogger<ApplicationInHostService> logger) : base(logger)
{
this.dataContext = dataContext;
this.logger = logger;
}
protected override DbSet<ApplicationInHost> EntitySet => dataContext.ApplicationsInHosts;
protected override DataContext EntitiContext => dataContext;
}
}

View File

@@ -2,25 +2,14 @@
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class ApplicationService : BaseService<Application>, IApplicationService
internal class ApplicationService : BaseRepository<Application>, IApplicationService
{
private readonly DataContext dataContext;
private readonly ILogger<ApplicationService> logger;
public ApplicationService(DataContext dataContext, ILogger<ApplicationService> logger) : base(logger)
{
this.dataContext = dataContext;
this.logger = logger;
}
protected override DbSet<Application> EntitySet => dataContext.Applications;
protected override DataContext EntitiContext => dataContext;
public ApplicationService(DataContext dataContext, ILogger<ApplicationService> logger) : base(logger, dataContext) { }
public async Task<Application?> GetByNameAsync(string appName, Guid typeId)
{

View File

@@ -1,25 +1,14 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementation
{
internal class ApplicationTypeService : BaseService<ApplicationType>, IApplicationTypeService
internal class ApplicationTypeService : BaseRepository<ApplicationType>, IApplicationTypeService
{
private readonly DataContext dataContext;
private readonly ILogger<ApplicationTypeService> logger;
public ApplicationTypeService(DataContext dataContext, ILogger<ApplicationTypeService> logger) : base(logger, dataContext) { }
public ApplicationTypeService(DataContext dataContext, ILogger<ApplicationTypeService> logger) : base(logger)
{
this.dataContext = dataContext;
this.logger = logger;
}
protected override DbSet<ApplicationType> EntitySet => dataContext.ApplicationTypes;
protected override DataContext EntitiContext => dataContext;
}
}

View File

@@ -2,26 +2,14 @@
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class ApplicationsInWorkService : BaseService<ApplicationsInWork>, IApplicationsInWorkService
internal class ApplicationsInWorkService : BaseRepository<ApplicationsInWork>, IApplicationsInWorkService
{
private readonly DataContext dataContext;
private readonly ILogger<ApplicationsInWorkService> logger;
public ApplicationsInWorkService(DataContext dataContext, ILogger<ApplicationsInWorkService> logger) : base(logger)
{
this.dataContext = dataContext;
this.logger = logger;
}
protected override DbSet<ApplicationsInWork> EntitySet => dataContext.ApplicationsInWorks;
protected override DataContext EntitiContext => dataContext;
public ApplicationsInWorkService(DataContext dataContext, ILogger<ApplicationsInWorkService> logger) : base(logger, dataContext) { }
public async Task<ApplicationsInWork?> GetAsync(Guid applicationId, Guid workId)
{

View File

@@ -1,23 +1,13 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class DistributionPeriodService : BaseService<DistributionPeriod>, IDistributionPeriodService
internal class DistributionPeriodService : BaseRepository<DistributionPeriod>, IDistributionPeriodService
{
private readonly DataContext dataContext;
protected override DbSet<DistributionPeriod> EntitySet => dataContext.DistributionPeriods;
protected override DataContext EntitiContext => dataContext;
public DistributionPeriodService(DataContext dataContext, ILogger<DistributionPeriodService> logger) : base(logger)
{
this.dataContext = dataContext;
}
public DistributionPeriodService(DataContext dataContext, ILogger<DistributionPeriodService> logger) : base(logger, dataContext) { }
}
}

View File

@@ -3,23 +3,14 @@ using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.DomainModels;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class EsppSchTypeConfigService : BaseService<EsppSchTypeConfig>, IEsppSchTypeConfigService
internal class EsppSchTypeConfigService : BaseRepository<EsppSchTypeConfig>, IEsppSchTypeConfigService
{
private readonly DataContext dataContext;
public EsppSchTypeConfigService(DataContext dataContext, ILogger<EsppSchTypeConfigService> logger) : base(logger)
{
this.dataContext = dataContext;
}
protected override DbSet<EsppSchTypeConfig> EntitySet => dataContext.EsppSchTypeConfigs;
protected override DataContext EntitiContext => dataContext;
public EsppSchTypeConfigService(DataContext dataContext, ILogger<EsppSchTypeConfigService> logger) : base(logger, dataContext) { }
public IQueryable<EsppSchTypeConfig> GetWithSchIncludes()
{
@@ -36,7 +27,7 @@ namespace PARR.DAL.Services.Implementations
{
//Формирует расписание в нормальном понятном виде из БД
var items = await dataContext.EsppSchValues.Where(t => t.JobGroupId == jobGroupId)
var items = await EntityContext.EsppSchValues.Where(t => t.JobGroupId == jobGroupId)
.Select(t => new
{
t.EsppSchTypeConfig!.Order,

View File

@@ -1,23 +1,13 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class EsppSchTypeValueService : BaseService<EsppSchTypeValue>, IEsppSchTypeValueService
internal class EsppSchTypeValueService : BaseRepository<EsppSchTypeValue>, IEsppSchTypeValueService
{
private readonly DataContext dataContext;
protected override DbSet<EsppSchTypeValue> EntitySet => dataContext.EsppSchTypeValues;
protected override DataContext EntitiContext => dataContext;
public EsppSchTypeValueService(DataContext dataContext, ILogger<EsppSchTypeValueService> logger): base(logger)
{
this.dataContext = dataContext;
}
public EsppSchTypeValueService(DataContext dataContext, ILogger<EsppSchTypeValueService> logger) : base(logger, dataContext) { }
}
}

View File

@@ -2,24 +2,14 @@
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class HostService : BaseService<Host>, IHostService
internal class HostService : BaseRepository<Host>, IHostService
{
private readonly DataContext dataContext;
private readonly ILogger<HostService> logger;
protected override DbSet<Host> EntitySet => dataContext.Hosts;
protected override DataContext EntitiContext => dataContext;
public HostService(DataContext dataContext, ILogger<HostService> logger) : base(logger)
{
this.dataContext = dataContext;
this.logger = logger;
}
public HostService(DataContext dataContext, ILogger<HostService> logger) : base(logger, dataContext) { }
public async Task<Host?> GetHostWithAppsByIpAsync(string ip)

View File

@@ -1,21 +1,12 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces.Job;
namespace PARR.DAL.Services.Implementations.Job
{
internal class FieldFilterService : BaseService<Models.Job.JobFieldFilter>, IFieldFilterService
internal class FieldFilterService : BaseRepository<Models.Job.JobFieldFilter>, IFieldFilterService
{
private readonly DataContext dataContext;
protected override DbSet<Models.Job.JobFieldFilter> EntitySet => dataContext.FieldFilters;
protected override DataContext EntitiContext => dataContext;
public FieldFilterService(DataContext dataContext, ILogger<FieldFilterService> logger) : base(logger)
{
this.dataContext = dataContext;
}
public FieldFilterService(DataContext dataContext, ILogger<FieldFilterService> logger) : base(logger, dataContext) { }
}
}

View File

@@ -1,23 +1,13 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models.Job;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces.Job;
namespace PARR.DAL.Services.Implementations.Job
{
internal class JobUnitFilterService : BaseService<JobUnitFilter>, IJobUnitFilterService
internal class JobUnitFilterService : BaseRepository<JobUnitFilter>, IJobUnitFilterService
{
private readonly DataContext dataContext;
protected override DbSet<JobUnitFilter> EntitySet => dataContext.JobUnitFilters;
protected override DataContext EntitiContext => dataContext;
public JobUnitFilterService(DataContext dataContext, ILogger<JobUnitFilterService> logger) : base(logger)
{
this.dataContext = dataContext;
}
public JobUnitFilterService(DataContext dataContext, ILogger<JobUnitFilterService> logger) : base(logger, dataContext) { }
}
}

View File

@@ -1,28 +1,19 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models.Job;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces.Job;
namespace PARR.DAL.Services.Implementations.Job
{
internal class JobGroupService : BaseService<Models.Job.JobGroup>, IJobGroupService
internal class JobGroupService : BaseRepository<Models.Job.JobGroup>, IJobGroupService
{
private readonly DataContext dataContext;
public JobGroupService(DataContext dataContext, ILogger<JobGroupService> logger) : base(logger)
{
this.dataContext = dataContext;
}
protected override DbSet<JobGroup> EntitySet => dataContext.JobGroups;
protected override DataContext EntitiContext => dataContext;
public JobGroupService(DataContext dataContext, ILogger<JobGroupService> logger) : base(logger, dataContext) { }
public void DeleteDistributionConfig(JobGroupDistributionConfig distributionConfig)
{
EntitiContext.JobGroupDistributionConfigs.Remove(distributionConfig);
EntityContext.JobGroupDistributionConfigs.Remove(distributionConfig);
}
}
}

View File

@@ -1,27 +1,13 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models.Job;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces.Job;
namespace PARR.DAL.Services.Implementations.Job
{
internal class JobGroupTypeService : BaseService<JobGroupType>, IJobGroupTypeService
internal class JobGroupTypeService : BaseRepository<JobGroupType>, IJobGroupTypeService
{
private readonly DataContext dataContext;
private readonly ILogger<JobGroupTypeService> logger;
protected override DbSet<JobGroupType> EntitySet => dataContext.JobGroupTypes;
protected override DataContext EntitiContext => dataContext;
public JobGroupTypeService(
DataContext dataContext,
ILogger<JobGroupTypeService> logger
) : base(logger)
{
this.dataContext = dataContext;
this.logger = logger;
}
public JobGroupTypeService(DataContext dataContext, ILogger<JobGroupTypeService> logger) : base(logger, dataContext) { }
}
}

View File

@@ -1,23 +1,13 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces.Job;
namespace PARR.DAL.Services.Implementations.Job
{
internal class JobService : BaseService<Models.Job.Job>, IJobService
internal class JobService : BaseRepository<Models.Job.Job>, IJobService
{
private readonly DataContext dataContext;
public JobService(DataContext dataContext, ILogger<JobService> logger) : base(logger)
{
this.dataContext = dataContext;
}
protected override DbSet<Models.Job.Job> EntitySet => dataContext.Jobs;
protected override DataContext EntitiContext => dataContext;
public JobService(DataContext dataContext, ILogger<JobService> logger) : base(logger, dataContext) { }
public override Task<bool> CreateAsync(Models.Job.Job obj)
{

View File

@@ -1,23 +1,13 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class OrderService : BaseService<Order>, IOrderService
internal class OrderService : BaseRepository<Order>, IOrderService
{
private readonly DataContext dataContext;
public OrderService(DataContext dataContext, ILogger<OrderService> logger) : base(logger)
{
this.dataContext = dataContext;
}
protected override DbSet<Order> EntitySet => dataContext.Orders;
protected override DataContext EntitiContext => dataContext;
public OrderService(DataContext dataContext, ILogger<OrderService> logger) : base(logger, dataContext) { }
}
}

View File

@@ -1,24 +1,14 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class ProcessService : BaseService<Process>, IProcessService
internal class ProcessService : BaseRepository<Process>, IProcessService
{
private readonly ILogger<ProcessService> logger;
private readonly DataContext dataContext;
public ProcessService(ILogger<ProcessService> logger, DataContext dataContext) : base(logger, dataContext) { }
public ProcessService(ILogger<ProcessService> logger, DataContext dataContext) : base(logger)
{
this.logger = logger;
this.dataContext = dataContext;
}
protected override DbSet<Process> EntitySet => dataContext.Processes;
protected override DataContext EntitiContext => dataContext;
}
}

View File

@@ -3,26 +3,15 @@ using Microsoft.Extensions.Logging;
using PARR.Constants;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
using PARR.Domain.Enums;
namespace PARR.DAL.Services.Implementations
{
internal class RobotConfigurationService : BaseService<RobotConfiguration>, IRobotConfigurationService
internal class RobotConfigurationService : BaseRepository<RobotConfiguration>, IRobotConfigurationService
{
private readonly DataContext dataContext;
private readonly ILogger<RobotConfigurationService> logger;
public RobotConfigurationService(DataContext dataContext, ILogger<RobotConfigurationService> logger) : base(logger)
{
this.dataContext = dataContext;
this.logger = logger;
}
protected override DbSet<RobotConfiguration> EntitySet => dataContext.RobotConfigurations;
protected override DataContext EntitiContext => dataContext;
public RobotConfigurationService(DataContext dataContext, ILogger<RobotConfigurationService> logger) : base(logger, dataContext) { }
public void ChangeTaskStatus(TaskStatusEnum taskStatus, RobotConfiguration configuration)

View File

@@ -1,23 +1,14 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class RobotHistoryService : BaseService<RobotHistory>, IRobotHistoryService
internal class RobotHistoryService : BaseRepository<RobotHistory>, IRobotHistoryService
{
private readonly DataContext dataContext;
public RobotHistoryService(DataContext dataContext, ILogger<RobotHistoryService> logger) : base(logger, dataContext) { }
public RobotHistoryService(DataContext dataContext, ILogger<RobotHistoryService> logger) : base(logger)
{
this.dataContext = dataContext;
}
protected override DbSet<RobotHistory> EntitySet => dataContext.RobotHistories;
protected override DataContext EntitiContext => dataContext;
}
}

View File

@@ -1,23 +1,13 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class RoleService : BaseService<Role>, IRoleService
internal class RoleService : BaseRepository<Role>, IRoleService
{
private readonly DataContext dataContext;
public RoleService(DataContext dataContext, ILogger<RoleService> logger) : base(logger)
{
this.dataContext = dataContext;
}
protected override DbSet<Role> EntitySet => dataContext.Roles;
protected override DataContext EntitiContext => dataContext;
public RoleService(DataContext dataContext, ILogger<RoleService> logger) : base(logger, dataContext) { }
}
}

View File

@@ -1,23 +1,13 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models.Schedule;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces.Schedule;
namespace PARR.DAL.Services.Implementations.Schedule
{
internal class ScheduleExcludeTypeCalendarService : BaseService<ScheduleExcludeTypeCalendar>, IScheduleExcludeTypeCalendarService
internal class ScheduleExcludeTypeCalendarService : BaseRepository<ScheduleExcludeTypeCalendar>, IScheduleExcludeTypeCalendarService
{
private readonly DataContext dataContext;
protected override DbSet<ScheduleExcludeTypeCalendar> EntitySet => dataContext.ScheduleExcludeTypeCalendars;
protected override DataContext EntitiContext => dataContext;
public ScheduleExcludeTypeCalendarService(DataContext dataContext, ILogger<ScheduleExcludeTypeCalendarService> logger) : base(logger)
{
this.dataContext = dataContext;
}
public ScheduleExcludeTypeCalendarService(DataContext dataContext, ILogger<ScheduleExcludeTypeCalendarService> logger) : base(logger, dataContext) { }
}
}

View File

@@ -1,23 +1,13 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models.Schedule;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces.Schedule;
namespace PARR.DAL.Services.Implementations.Schedule
{
internal class ScheduleExcludeTypeService : BaseService<ScheduleExcludeType>, IScheduleExcludeTypeService
internal class ScheduleExcludeTypeService : BaseRepository<ScheduleExcludeType>, IScheduleExcludeTypeService
{
private readonly DataContext dataContext;
protected override DbSet<ScheduleExcludeType> EntitySet => dataContext.ScheduleExcludeTypes;
protected override DataContext EntitiContext => dataContext;
public ScheduleExcludeTypeService(DataContext dataContext, ILogger<ScheduleExcludeTypeService> logger) : base(logger)
{
this.dataContext = dataContext;
}
public ScheduleExcludeTypeService(DataContext dataContext, ILogger<ScheduleExcludeTypeService> logger) : base(logger, dataContext) { }
}
}

View File

@@ -10,10 +10,12 @@ namespace PARR.DAL.Services.Implementations.Schedule
internal sealed class ScheduleResponseAreaTimeOffsetService : IScheduleResponseAreaTimeOffsetService
{
private readonly IReadOnlyDictionary<string, ScheduleResponseAreaTimeOffset> offsetList;
/// <summary>
/// ЗО по умолчанию
/// </summary>
private readonly string defaultResponseArea;
/// <summary>
/// Настройки, если не нашли в offsetList
/// </summary>

View File

@@ -1,24 +1,14 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class SubprocessService : BaseService<Subprocess>, ISubprocessService
internal class SubprocessService : BaseRepository<Subprocess>, ISubprocessService
{
private readonly ILogger<SubprocessService> logger;
private readonly DataContext dataContext;
public SubprocessService(ILogger<SubprocessService> logger, DataContext dataContext) : base(logger, dataContext) { }
public SubprocessService(ILogger<SubprocessService> logger, DataContext dataContext) : base(logger)
{
this.logger = logger;
this.dataContext = dataContext;
}
protected override DbSet<Subprocess> EntitySet => dataContext.Subprocesses;
protected override DataContext EntitiContext => dataContext;
}
}

View File

@@ -1,23 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Services.Interfaces.TaskServices;
using PARR.Domain.Entities.TaskEntities;
namespace PARR.DAL.Services.Implementations.TaskServices
{
internal class TaskErrorService : BaseService<TaskError>, ITaskErrorService
{
private readonly DataContext dataContext;
protected override DbSet<TaskError> EntitySet => dataContext.TaskErrors;
protected override DataContext EntitiContext => dataContext;
public TaskErrorService(DataContext dataContext, ILogger<TaskErrorService> logger): base(logger)
{
this.dataContext = dataContext;
}
}
}

View File

@@ -1,26 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Services.Interfaces.TaskServices;
using PARR.Domain.Entities.TaskEntities;
namespace PARR.DAL.Services.Implementations.TaskServices
{
internal class TaskService : BaseService<TaskItem>, ITaskService
{
private readonly DataContext dataContext;
protected override DbSet<TaskItem> EntitySet => dataContext.Tasks;
protected override DataContext EntitiContext => dataContext;
public TaskService(DataContext dataContext, ILogger<TaskService> logger) : base(logger)
{
this.dataContext = dataContext;
}
// метод атомарного взятия в работу
}
}

View File

@@ -1,21 +0,0 @@
using PARR.DAL.Context;
using PARR.DAL.Services.Interfaces.TaskServices;
using PARR.Domain.Entities.TaskEntities;
namespace PARR.DAL.Services.Implementations.TaskServices
{
internal class TaskTypeService : ITaskTypeService
{
private readonly DataContext dataContext;
public TaskTypeService(DataContext dataContext)
{
this.dataContext = dataContext;
}
public IQueryable<TaskType> Get()
{
return dataContext.TaskTypes;
}
}
}

View File

@@ -1,23 +1,13 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class TemplateHistoryService : BaseService<TemplateHistory>, ITemplateHistoryService
internal class TemplateHistoryService : BaseRepository<TemplateHistory>, ITemplateHistoryService
{
private readonly DataContext dataContext;
protected override DbSet<TemplateHistory> EntitySet => dataContext.TemplateHistories;
protected override DataContext EntitiContext => dataContext;
public TemplateHistoryService(DataContext dataContext, ILogger<TemplateHistoryService> logger) : base(logger)
{
this.dataContext = dataContext;
}
public TemplateHistoryService(DataContext dataContext, ILogger<TemplateHistoryService> logger) : base(logger, dataContext) { }
}
}

View File

@@ -4,27 +4,16 @@ using Npgsql;
using PARR.Constants;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
using PARR.Domain.Entities.Base.History;
using PARR.Domain.Enums;
namespace PARR.DAL.Services.Implementations
{
internal class TemplateService : BaseService<Template>, ITemplateService
internal class TemplateService : BaseRepository<Template>, ITemplateService
{
private readonly DataContext dataContext;
private readonly ILogger<TemplateService> logger;
protected override DbSet<Template> EntitySet => dataContext.Templates;
protected override DataContext EntitiContext => dataContext;
public TemplateService(DataContext dataContext, ILogger<TemplateService> logger) : base(logger)
{
this.dataContext = dataContext;
this.logger = logger;
}
public TemplateService(DataContext dataContext, ILogger<TemplateService> logger) : base(logger, dataContext) { }
public async Task<Template?> GetTemplateByNameAsync(string name)
{
@@ -167,7 +156,7 @@ namespace PARR.DAL.Services.Implementations
try
{
var result = await dataContext.Database
var result = await EntityContext.Database
.SqlQueryRaw<Guid>(sql, parameters)
.ToListAsync();

View File

@@ -1,24 +1,14 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class TnkService : BaseService<Tnk>, ITnkService
internal class TnkService : BaseRepository<Tnk>, ITnkService
{
private readonly ILogger<TnkService> logger;
private readonly DataContext dataContext;
public TnkService(ILogger<TnkService> logger, DataContext dataContext) : base(logger, dataContext) { }
public TnkService(ILogger<TnkService> logger, DataContext dataContext) : base(logger)
{
this.logger = logger;
this.dataContext = dataContext;
}
protected override DbSet<Tnk> EntitySet => dataContext.Tnks;
protected override DataContext EntitiContext => dataContext;
}
}

View File

@@ -2,23 +2,14 @@
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models.Unit;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces.Unit;
namespace PARR.DAL.Services.Implementations.Unit
{
internal class UnitFieldService : BaseService<UnitField>, IUnitFieldService
internal class UnitFieldService : BaseRepository<UnitField>, IUnitFieldService
{
private readonly DataContext dataContext;
protected override DbSet<UnitField> EntitySet => dataContext.UnitFields;
protected override DataContext EntitiContext => dataContext;
public UnitFieldService(DataContext dataContext, ILogger<UnitFieldService> logger) : base(logger)
{
this.dataContext = dataContext;
}
public UnitFieldService(DataContext dataContext, ILogger<UnitFieldService> logger) : base(logger, dataContext) { }
public async Task<UnitField?> GetByAihitNameAsync(string name)
{

View File

@@ -2,23 +2,14 @@
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models.Unit;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces.Unit;
namespace PARR.DAL.Services.Implementations.Unit
{
internal class UnitFieldValueService : BaseService<UnitFieldValue>, IUnitFieldValueService
internal class UnitFieldValueService : BaseRepository<UnitFieldValue>, IUnitFieldValueService
{
private readonly DataContext dataContext;
protected override DbSet<UnitFieldValue> EntitySet => dataContext.UnitFieldValues;
protected override DataContext EntitiContext => dataContext;
public UnitFieldValueService(DataContext dataContext, ILogger<UnitFieldValueService> logger) : base(logger)
{
this.dataContext = dataContext;
}
public UnitFieldValueService(DataContext dataContext, ILogger<UnitFieldValueService> logger) : base(logger, dataContext) { }
public async Task<UnitFieldValue?> GetByValueNameAsync(string? value)
@@ -26,7 +17,7 @@ namespace PARR.DAL.Services.Implementations.Unit
var query = EntitySet
.Include(v => v.FieldValues);
if (string.IsNullOrWhiteSpace(value))
if (string.IsNullOrWhiteSpace(value))
return await query.FirstOrDefaultAsync(uf => uf.Value == null);
return await query.FirstOrDefaultAsync(uf => uf.Value!.ToLower().Trim() == value.ToLower().Trim());

View File

@@ -1,23 +1,14 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces.Unit;
namespace PARR.DAL.Services.Implementations.Unit
{
internal class UnitService : BaseService<Models.Unit.Unit>, IUnitService
internal class UnitService : BaseRepository<Models.Unit.Unit>, IUnitService
{
private readonly DataContext dataContext;
protected override DbSet<Models.Unit.Unit> EntitySet => dataContext.Units;
protected override DataContext EntitiContext => dataContext;
public UnitService(DataContext dataContext, ILogger<UnitService> logger) : base(logger)
{
this.dataContext = dataContext;
}
public UnitService(DataContext dataContext, ILogger<UnitService> logger) : base(logger, dataContext) { }
public IQueryable<Models.Unit.Unit> GetWithIncludes()

View File

@@ -2,23 +2,14 @@
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class UserService : BaseService<User>, IUserService
internal class UserService : BaseRepository<User>, IUserService
{
private readonly DataContext dataContext;
public UserService(DataContext dataContext, ILogger<UserService> logger) : base(logger)
{
this.dataContext = dataContext;
}
protected override DbSet<User> EntitySet => dataContext.Users;
protected override DataContext EntitiContext => dataContext;
public UserService(DataContext dataContext, ILogger<UserService> logger) : base(logger, dataContext) { }
public async Task<User?> GetByIpWithRolesAsync(string ipAddress)
{

View File

@@ -4,31 +4,23 @@ using PARR.DAL.Cache.Services.Base;
using PARR.DAL.Context;
using PARR.DAL.Contracts;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class WeekendDayService : BaseService<WeekendDay>, IWeekendDayService
internal class WeekendDayService : BaseRepository<WeekendDay>, IWeekendDayService
{
private readonly DataContext dataContext;
private readonly ILogger<WeekendDayService> logger;
private readonly IRedisCacheService redisCacheService;
private readonly SettingsFromDb settings;
protected override DbSet<WeekendDay> EntitySet => dataContext.WeekendDays;
protected override DataContext EntitiContext => dataContext;
public WeekendDayService(
DataContext dataContext,
ILogger<WeekendDayService> logger,
IRedisCacheService redisCacheService,
SettingsFromDb settings
) : base(logger)
) : base(logger, dataContext)
{
this.dataContext = dataContext;
this.logger = logger;
this.redisCacheService = redisCacheService;
this.settings = settings;
}
@@ -102,12 +94,14 @@ namespace PARR.DAL.Services.Implementations
private string GetWeekendKey(DateOnly day)
{
return $"weekend_{day.ToString("yyyy-MM-dd")}";
// return $"weekend_{day.ToString("yyyy-MM-dd")}";
return redisCacheService.GetKey(new[] { "weekend", day.ToString("yyyy-MM-dd") });
}
private string GetWorkDayKey(DateOnly day)
{
return $"workday_{day.ToString("yyyy-MM-dd")}";
//return $"workday_{day.ToString("yyyy-MM-dd")}";
return redisCacheService.GetKey(new[] { "workday", day.ToString("yyyy-MM-dd") });
}
}

View File

@@ -2,24 +2,15 @@
using Microsoft.Extensions.Logging;
using PARR.DAL.Context;
using PARR.DAL.Models;
using PARR.DAL.Services.Abstracts;
using PARR.DAL.Repositories.Base;
using PARR.DAL.Services.Interfaces;
namespace PARR.DAL.Services.Implementations
{
internal class WorkGroupService : BaseService<WorkGroup>, IWorkGroupService
internal class WorkGroupService : BaseRepository<WorkGroup>, IWorkGroupService
{
private readonly DataContext dataContext;
private readonly ILogger<WorkGroupService> logger;
public WorkGroupService(DataContext dataContext, ILogger<WorkGroupService> logger) : base(logger, dataContext) { }
protected override DbSet<WorkGroup> EntitySet => dataContext.WorkGroups;
protected override DataContext EntitiContext => dataContext;
public WorkGroupService(DataContext dataContext, ILogger<WorkGroupService> logger) : base(logger)
{
this.dataContext = dataContext;
this.logger = logger;
}
public async Task<WorkGroup?> GetByNameAsync(string name)
{
return await Get().FirstOrDefaultAsync(t => t.Name == name);

View File

@@ -1,22 +1,41 @@
using PARR.DAL.DomainModels;
using PARR.Core.Repositories.Base;
using PARR.Domain.Entities.Base;
using PARR.Domain.Entities.Base.History;
namespace PARR.DAL.Services.Interfaces.Base
{
public interface IBaseService<T> where T : class, IBaseEntity
public interface IBaseService<T> : IBaseRepository<T> where T : class, IBaseEntity
{
Task<T?> GetAsync(Guid id);
IQueryable<T> Get();
IQueryable<T> GetPage(IQueryable<T> query, PaginationFilter paginationFilter);
// TODO: позже удалить этот интерфейс, когда изменим все сервисы на репозитории
Task<bool> CreateAsync(T obj);
Task<bool> AddRangeAsync(List<T> objs);
//Task<T?> GetAsync(Guid id);
//IQueryable<T> Get();
//IQueryable<T> GetPage(IQueryable<T> query, PaginationFilter paginationFilter);
Task<bool> DeleteAsync(Guid id);
bool Delete(T obj);
//Task<bool> CreateAsync(T obj);
//Task<bool> AddRangeAsync(List<T> objs);
//Task<bool> CommitAsync();
Task<bool> CommitAsync(IHistoryInitiator? initiator = null);
//Task<bool> DeleteAsync(Guid id);
//bool Delete(T obj);
////Task<bool> CommitAsync();
//Task<bool> CommitAsync(IHistoryInitiator? initiator = null);
}
//public interface IBaseService<T> where T : class, IBaseEntity
//{
// Task<T?> GetAsync(Guid id);
// IQueryable<T> Get();
// IQueryable<T> GetPage(IQueryable<T> query, PaginationFilter paginationFilter);
// Task<bool> CreateAsync(T obj);
// Task<bool> AddRangeAsync(List<T> objs);
// Task<bool> DeleteAsync(Guid id);
// bool Delete(T obj);
// //Task<bool> CommitAsync();
// Task<bool> CommitAsync(IHistoryInitiator? initiator = null);
//}
}

View File

@@ -1,9 +0,0 @@
using PARR.DAL.Services.Interfaces.Base;
using PARR.Domain.Entities.TaskEntities;
namespace PARR.DAL.Services.Interfaces.TaskServices
{
public interface ITaskErrorService : IBaseService<TaskError>
{
}
}

View File

@@ -1,9 +0,0 @@
using PARR.DAL.Services.Interfaces.Base;
using PARR.Domain.Entities.TaskEntities;
namespace PARR.DAL.Services.Interfaces.TaskServices
{
public interface ITaskService : IBaseService<TaskItem>
{
}
}

View File

@@ -1,9 +0,0 @@
using PARR.Domain.Entities.TaskEntities;
namespace PARR.DAL.Services.Interfaces.TaskServices
{
public interface ITaskTypeService
{
IQueryable<TaskType> Get();
}
}