public void StartLoadingProductRemains(string sku) { var thisProduct = _products.FirstOrDefault(x => x.Sku == sku); if (thisProduct != null && thisProduct.CountState == Enums.RequestState.Succseeded) { OnProductRemainsReceived?.Invoke(sku, thisProduct.Count); } var tiket = _catalogRepository.GetRemainsTicket(sku); tiket.OnSuccess += (response) => { if (response.Data?.Sku != null) { if (thisProduct == null) { thisProduct = new CatalogueProduct() { Sku = sku }; _products.Add(thisProduct); } thisProduct.Count = response.Data.Count; thisProduct.CountState = Enums.RequestState.Succseeded; OnProductRemainsReceived?.Invoke(thisProduct.Sku, thisProduct.Count); return; } OnProductPriceReceived?.Invoke(null, null); }; }
public CatalogueService() { _products = new List <CatalogueProduct>(); _catalogRepository = Core.DI.Container.GetInstance <ICatalogRepository>(); _catalogRepository.OnProductRemainsChanging += (sku, count) => { OnProductRemainsReceived?.Invoke(sku, count); }; }