diff --git a/TIAMSharedUI/Shared/ComboboxItemSelector.razor b/TIAMSharedUI/Shared/ComboboxItemSelector.razor index 9195bb66..fce38927 100644 --- a/TIAMSharedUI/Shared/ComboboxItemSelector.razor +++ b/TIAMSharedUI/Shared/ComboboxItemSelector.razor @@ -1,7 +1,9 @@ @using System.Linq.Expressions @using AyCode.Core.Extensions +@using AyCode.Core.Helpers @using AyCode.Core.Loggers @using AyCode.Services.Loggers +@using AyCode.Services.SignalRs @using TIAM.Core.Loggers @using TIAM.Entities.Products @using TIAM.Entities.Transfers @@ -79,7 +81,7 @@ [Parameter] public Guid? ProductId { get; set; } - public List Destinations = new List(); + public List Destinations = []; public DxTextBox TextField; @@ -87,22 +89,21 @@ ILogger _logger; - IEnumerable Data { get; set; } + List Data { get; set; } = []; private string Address { get; set; } private string ValidationMessage { get; set; } - private TransferDestination _selectedDestination; - public TransferDestination SelectedDestination + private TransferDestination? _selectedDestination; + public TransferDestination? SelectedDestination { get => _selectedDestination; set { - if (_selectedDestination != value) - { - _selectedDestination = value; - SetNewDestination(value.AddressString!); - } + if (_selectedDestination == value) return; + + _selectedDestination = value; + SetNewDestination(value?.AddressString ?? string.Empty); } } @@ -115,8 +116,6 @@ { _logger = new LoggerClient(LogWriters.ToArray()); - Data = await _adminSignalRClient.GetAllAsync>(SignalRTags.GetAllTransferDestinations); - Guid? productAddressId = Guid.Empty; if (!ProductId.IsNullOrEmpty()) { @@ -130,16 +129,28 @@ } } - _logger.Debug($"List length: {Data.Count().ToString()}"); - if (Data.Any(x => x.AddressId == (Guid)productAddressId)) + _adminSignalRClient.GetAllAsync>(SignalRTags.GetAllTransferDestinations, response => { - SelectedDestination = Data.Where(x => x.AddressId == (Guid)productAddressId).FirstOrDefault()!; - } - else - { - SelectedDestination = Data.FirstOrDefault(); - } + Data.Clear(); + SelectedDestination = null; + + if (response.Status != SignalResponseStatus.Success || response.ResponseData == null) + { + _logger.Error($"OnInitializedAsync->GetAllTransferDestinations; response.Status: {response.Status}"); + return Task.CompletedTask; + } + + Data.AddRange(response.ResponseData); + + _logger.Debug($"TransferDestinations Data length: {Data.Count}"); + SelectedDestination = productAddressId.IsNullOrEmpty() ? Data.FirstOrDefault() : Data.FirstOrDefault(x => x.AddressId == productAddressId); + + return Task.CompletedTask; + }).Forget(); + + //await _adminSignalRClient.GetAllIntoAsync(Data, SignalRTags.GetAllTransferDestinations); } + // RenderFragment GetSelectedItemDescription() // { // if (SelectedDestination != null) diff --git a/TIAMWebApp/Shared/Services/AdminSignalRClient.cs b/TIAMWebApp/Shared/Services/AdminSignalRClient.cs index 09889a38..e87959cd 100644 --- a/TIAMWebApp/Shared/Services/AdminSignalRClient.cs +++ b/TIAMWebApp/Shared/Services/AdminSignalRClient.cs @@ -61,9 +61,9 @@ namespace TIAMWebApp.Shared.Application.Services //TODO: AdminSignalRClient.GetAllIntoAsync(_cars, SignalRTags.GetAllCarsByProductId, [productId]) - J. return GetAllAsync>(SignalRTags.GetAllCarsByProductId, response => { + intoCars.Clear(); if (response is { Status: SignalResponseStatus.Success, ResponseData: not null }) { - intoCars.Clear(); intoCars.AddRange(response.ResponseData); }