69 lines
2.4 KiB
C#
69 lines
2.4 KiB
C#
namespace EgwCoreLib.Lux.Data.Repository.Items
|
|
{
|
|
public class ItemGroupRepository : BaseRepository, IItemGroupRepository
|
|
{
|
|
#region Public Constructors
|
|
|
|
public ItemGroupRepository(IDbContextFactory<DataLayerContext> ctxFactory) : base(ctxFactory)
|
|
{
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> AddMissingAsync(List<BomItemDTO> bomList)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
bool fatto = false;
|
|
// recupero lista esistenti
|
|
var itemGroupList = await dbCtx.DbSetItemGroup
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
|
|
// calcolo i distinct dei CodGroup x eventuale insert preventivo
|
|
List<string> distCodGroups = bomList
|
|
.Select(i => i.ClassCode)
|
|
.Distinct()
|
|
.Where(c => !string.IsNullOrWhiteSpace(c))
|
|
.ToList();
|
|
|
|
// elenco da inserire...
|
|
var codGroupsToInsert = distCodGroups
|
|
.Where(x => !itemGroupList.Any(i => i.CodGroup == x))
|
|
.Select(x => new ItemGroupModel() { CodGroup = x, Description = x })
|
|
.ToList();
|
|
// se ci sono inserisco!
|
|
if (codGroupsToInsert != null && codGroupsToInsert.Count > 0)
|
|
{
|
|
await dbCtx
|
|
.DbSetItemGroup
|
|
.AddRangeAsync(codGroupsToInsert);
|
|
|
|
// e salvo
|
|
fatto = await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> AddRangeAsync(List<ItemGroupModel> entityList)
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
await dbCtx.DbSetItemGroup.AddRangeAsync(entityList);
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<ItemGroupModel>> GetAllAsync()
|
|
{
|
|
await using var dbCtx = await CreateContextAsync();
|
|
return await dbCtx.DbSetItemGroup
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |