@using AyCode.Core.Helpers
@using DevExpress.Internal.About
@using FruitBank.Common.Dtos
@using FruitBankHybrid.Shared.Services.SignalRs
@inject FruitBankSignalRClient FruitBankSignalRClient
@if (IsMasterGrid)
{
var productId = ((ProductDto)context.DataItem).Id;
@{
//GetOrderDtosFromDbAsync(productId).Forget();
//var orderDtos = _orderDtos?.Where(o => o.OrderItemDtos.Any(oi => oi.ProductId == productId)).ToList() ?? [];
}
@{
//GetOrderItemDtosFromDbAsync(productId).Forget();
//var orderItemDtos = _orderItemDtos?.Where(oi => oi.ProductId == productId).ToList() ?? [];
}
}
@code {
private int _activeTabIndex;
private List? _currentOrderDtos;
private List? _currentOrderItemDtos;
private readonly Dictionary> _orderDtosByProductId = new();
private readonly Dictionary> _orderItemDtosByProductId = new();
[Parameter] public bool IsMasterGrid { get; set; } = false;
[Parameter] public List? ProductDtos { get; set; }
//[Parameter] public List? OrderDtos { get; set; }
//[Parameter] public List? OrderItemDtos { get; set; }
protected override async Task OnInitializedAsync()
{
ProductDtos ??= await FruitBankSignalRClient.GetProductDtos();
// if (ProductDtos is { Count: > 0 })
// _currentOrderDtos = await GetOrderDtosFromDbAsync(ProductDtos[0].Id);
}
private async Task> GetOrderDtosFromDbAsync(int productId)
{
if (_orderDtosByProductId.TryGetValue(productId, out var orderDtos)) return orderDtos;
orderDtos = await FruitBankSignalRClient.GetAllOrderDtoByProductId(productId) ?? [];
_orderDtosByProductId[productId] = orderDtos;
return _currentOrderDtos = orderDtos;
}
private async Task> GetOrderItemDtosFromDbAsync(int productId)
{
if (_orderItemDtosByProductId.TryGetValue(productId, out var orderItemDtos)) return orderItemDtos;
orderItemDtos = await FruitBankSignalRClient.GetAllOrderItemDtoByProductId(productId) ?? [];
_orderItemDtosByProductId[productId] = orderItemDtos;
return _currentOrderItemDtos = orderItemDtos;
}
protected async Task OnFocusedRowChanged(GridFocusedRowChangedEventArgs e)
{
var productDto = (ProductDto)e.DataItem;
//if (e.Grid.IsDetailRowExpanded(e.VisibleIndex))
{
_currentOrderDtos = null;
_currentOrderDtos = productDto != null ? await GetOrderDtosFromDbAsync(productDto.Id) : [];
}
}
protected async Task OnActiveTabChanged(int activeTabIndex, int productId)
{
_activeTabIndex = activeTabIndex;
switch (_activeTabIndex)
{
case 0:
//_currentOrderDtos = null;
_currentOrderDtos = await GetOrderDtosFromDbAsync(productId);
break;
case 1:
_currentOrderItemDtos = null;
_currentOrderItemDtos = await GetOrderItemDtosFromDbAsync(productId);
break;
}
}
}