2024-07-04 11:02:45 +05:00
|
|
|
using AsbCloudApp.Repositories;
|
2024-02-08 11:38:25 +05:00
|
|
|
using AsbCloudDb.Model;
|
|
|
|
using Mapster;
|
|
|
|
using Microsoft.Extensions.Caching.Memory;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2024-03-20 12:52:28 +05:00
|
|
|
using AsbCloudApp.Data.WellOperation;
|
2024-02-08 11:38:25 +05:00
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Repository;
|
|
|
|
|
|
|
|
public class WellOperationCategoryRepository : IWellOperationCategoryRepository
|
|
|
|
{
|
|
|
|
private readonly IAsbCloudDbContext db;
|
|
|
|
private readonly IMemoryCache memoryCache;
|
|
|
|
|
|
|
|
public WellOperationCategoryRepository(IAsbCloudDbContext db, IMemoryCache memoryCache)
|
|
|
|
{
|
|
|
|
this.db = db;
|
|
|
|
this.memoryCache = memoryCache;
|
|
|
|
}
|
|
|
|
|
2024-04-10 15:05:15 +05:00
|
|
|
public IEnumerable<WellOperationCategoryDto> Get(bool includeParents, bool includeHidden = true)
|
2024-02-08 11:38:25 +05:00
|
|
|
{
|
|
|
|
var categories = memoryCache
|
|
|
|
.GetOrCreateBasic(db.Set<WellOperationCategory>());
|
|
|
|
|
2024-04-15 10:42:01 +05:00
|
|
|
if (!includeHidden)
|
|
|
|
categories = categories.Where(o => o.IsHidden == false);
|
2024-04-10 15:05:15 +05:00
|
|
|
|
2024-02-08 11:38:25 +05:00
|
|
|
if (!includeParents)
|
|
|
|
{
|
|
|
|
var parentIds = categories
|
|
|
|
.Select(o => o.IdParent)
|
|
|
|
.Distinct();
|
|
|
|
|
|
|
|
categories = categories
|
|
|
|
.Where(o => !parentIds.Contains(o.Id));
|
|
|
|
}
|
|
|
|
|
|
|
|
var result = categories
|
|
|
|
.OrderBy(o => o.Name)
|
|
|
|
.Adapt<IEnumerable<WellOperationCategoryDto>>();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|