improvements

This commit is contained in:
Loretta 2025-10-15 15:42:18 +02:00
parent d5f8666a8d
commit fbf83e5736
2 changed files with 13 additions and 12 deletions

View File

@ -131,17 +131,17 @@ public class FruitBankDbContext : MgDbContextBase,
=> GetAllProducts(includeDeleted).Select(product => new ProductDto(product)); => GetAllProducts(includeDeleted).Select(product => new ProductDto(product));
public IAsyncEnumerable<MeasuringProductDto> GetAllMeasuringProductDtos(bool includeDeleted) public IAsyncEnumerable<MeasuringProductDto> GetAllMeasuringProductDtos(bool includeDeleted)
=> GetAllProducts(includeDeleted).SelectAwait(async product => new MeasuringProductDto(product, await GetMeasuringAttributeValuesByProductIdAsync(product.Id))); => GetAllProducts(includeDeleted).AsEnumerable().SelectAwait(async product => new MeasuringProductDto(product, await GetMeasuringAttributeValuesByProductIdAsync(product.Id)));
public async Task<MeasuringProductDto?> GetMeasuringProductDtoByIdAsync(int productId) public async Task<MeasuringProductDto?> GetMeasuringProductDtoByIdAsync(int productId)
=> await Products.Table.Where(product => product.Id == productId).SelectAwait(async product => new MeasuringProductDto(product, await GetMeasuringAttributeValuesByProductIdAsync(product.Id))).FirstOrDefaultAsync(); => await Products.Table.Where(product => product.Id == productId).AsEnumerable().SelectAwait(async product => new MeasuringProductDto(product, await GetMeasuringAttributeValuesByProductIdAsync(product.Id))).FirstOrDefaultAsync();
public async Task<MeasuringAttributeValues?> GetMeasuringAttributeValuesByProductIdAsync(int productId) public async Task<MeasuringAttributeValues?> GetMeasuringAttributeValuesByProductIdAsync(int productId)
=> await _fruitBankAttributeService.GetMeasuringAttributeValuesAsync<Product>(productId); => await _fruitBankAttributeService.GetMeasuringAttributeValuesAsync<Product>(productId);
public async Task DeleteShippingSafeAsync(Shipping shipping) public async Task DeleteShippingSafeAsync(Shipping shipping)
{ {
await TransactionSafeAsync(async tr => await TransactionSafeAsync(async _ =>
{ {
await Shippings.DeleteAsync(shipping, true); await Shippings.DeleteAsync(shipping, true);
return true; return true;
@ -150,7 +150,7 @@ public class FruitBankDbContext : MgDbContextBase,
public async Task DeleteShippingDocumentSafeAsync(ShippingDocument shippingDocument) public async Task DeleteShippingDocumentSafeAsync(ShippingDocument shippingDocument)
{ {
await TransactionSafeAsync(async tr => await TransactionSafeAsync(async _ =>
{ {
await ShippingDocuments.DeleteAsync(shippingDocument, true); await ShippingDocuments.DeleteAsync(shippingDocument, true);
return true; return true;
@ -159,7 +159,7 @@ public class FruitBankDbContext : MgDbContextBase,
public async Task DeleteShippingItemSafeAsync(ShippingItem shippingItem) public async Task DeleteShippingItemSafeAsync(ShippingItem shippingItem)
{ {
await TransactionSafeAsync(async tr => await TransactionSafeAsync(async _ =>
{ {
await ShippingItems.DeleteAsync(shippingItem, true); await ShippingItems.DeleteAsync(shippingItem, true);
return true; return true;
@ -306,7 +306,7 @@ public class FruitBankDbContext : MgDbContextBase,
} }
public Task<bool> AddShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet) public Task<bool> AddShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet)
=> TransactionSafeAsync(async tr => await AddShippingItemPalletAsync(shippingItemPallet) != null); => TransactionSafeAsync(async _ => await AddShippingItemPalletAsync(shippingItemPallet) != null);
public async Task<ShippingItemPallet?> UpdateShippingItemPalletAsync(ShippingItemPallet shippingItemPallet) public async Task<ShippingItemPallet?> UpdateShippingItemPalletAsync(ShippingItemPallet shippingItemPallet)
{ {
@ -317,13 +317,13 @@ public class FruitBankDbContext : MgDbContextBase,
} }
public Task<bool> UpdateShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet) public Task<bool> UpdateShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet)
=> TransactionSafeAsync(async tr => await UpdateShippingItemPalletAsync(shippingItemPallet) != null); => TransactionSafeAsync(async _ => await UpdateShippingItemPalletAsync(shippingItemPallet) != null);
public Task AddOrUpdateShippingItemPalletsSafeAsync(ShippingItem shippingItem) => AddOrUpdateShippingItemPalletsSafeAsync(shippingItem.ShippingItemPallets!, shippingItem); public Task AddOrUpdateShippingItemPalletsSafeAsync(ShippingItem shippingItem) => AddOrUpdateShippingItemPalletsSafeAsync(shippingItem.ShippingItemPallets!, shippingItem);
public Task<bool> AddOrUpdateShippingItemPalletsSafeAsync(IEnumerable<ShippingItemPallet> shippingItemPallets, ShippingItem parentShippingItem) public Task<bool> AddOrUpdateShippingItemPalletsSafeAsync(IEnumerable<ShippingItemPallet> shippingItemPallets, ShippingItem parentShippingItem)
{ {
return TransactionSafeAsync(async tr => return TransactionSafeAsync(async _ =>
{ {
await AddOrUpdateShippingItemPalletAsync(shippingItemPallets, parentShippingItem); await AddOrUpdateShippingItemPalletAsync(shippingItemPallets, parentShippingItem);
return true; return true;
@ -344,7 +344,7 @@ public class FruitBankDbContext : MgDbContextBase,
} }
public async Task<bool> AddOrUpdateShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet) public async Task<bool> AddOrUpdateShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet)
=> await TransactionSafeAsync(async tr => await AddOrUpdateShippingItemPalletAsync(shippingItemPallet) != null); => await TransactionSafeAsync(async _ => await AddOrUpdateShippingItemPalletAsync(shippingItemPallet) != null);
public async Task<ShippingItemPallet?> AddOrUpdateShippingItemPalletAsync(ShippingItemPallet shippingItemPallet) public async Task<ShippingItemPallet?> AddOrUpdateShippingItemPalletAsync(ShippingItemPallet shippingItemPallet)
{ {
@ -355,7 +355,7 @@ public class FruitBankDbContext : MgDbContextBase,
public async Task DeleteShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet) public async Task DeleteShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet)
{ {
await TransactionSafeAsync(async tr => await TransactionSafeAsync(async _ =>
{ {
await ShippingItemPallets.DeleteAsync(shippingItemPallet, false); await ShippingItemPallets.DeleteAsync(shippingItemPallet, false);
return true; return true;
@ -363,7 +363,7 @@ public class FruitBankDbContext : MgDbContextBase,
} }
public async Task<bool> SetOrderStatusToCompleteSafe(int orderId) public async Task<bool> SetOrderStatusToCompleteSafe(int orderId)
=> await TransactionSafeAsync(async tr => await SetOrderStatusToComplete(orderId) != null); => await TransactionSafeAsync(async _ => await SetOrderStatusToComplete(orderId) != null);
public async Task<OrderDto?> SetOrderStatusToComplete(int orderId) public async Task<OrderDto?> SetOrderStatusToComplete(int orderId)
{ {
@ -408,7 +408,7 @@ public class FruitBankDbContext : MgDbContextBase,
} }
public async Task<bool> AddOrUpdateOrderItemPalletSafeAsync(OrderItemPallet orderItemPallet) public async Task<bool> AddOrUpdateOrderItemPalletSafeAsync(OrderItemPallet orderItemPallet)
=> await TransactionSafeAsync(async tr => await AddOrUpdateOrderItemPalletAsync(orderItemPallet) != null); => await TransactionSafeAsync(async _ => await AddOrUpdateOrderItemPalletAsync(orderItemPallet) != null);
public async Task<OrderItemPallet?> AddOrUpdateOrderItemPalletAsync(OrderItemPallet orderItemPallet) public async Task<OrderItemPallet?> AddOrUpdateOrderItemPalletAsync(OrderItemPallet orderItemPallet)
{ {

View File

@ -43,6 +43,7 @@ public class OrderDtoDbTable : MgDbTableBase<OrderDto>
{ {
return GetAll() return GetAll()
.LoadWith(o => o.GenericAttributes) .LoadWith(o => o.GenericAttributes)
.LoadWith(o => o.Customer)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.ProductDto).ThenLoad(prod => prod.GenericAttributes) .LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.ProductDto).ThenLoad(prod => prod.GenericAttributes)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.GenericAttributes) .LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.GenericAttributes)
.LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.OrderItemPallets); .LoadWith(o => o.OrderItemDtos).ThenLoad(oi => oi.OrderItemPallets);