private void ReloadProducts(ProductChangedMessage message) { this.Products.Clear(); var products = this._serviceFactory.CreateClient <IInventoryService>().GetProducts(); foreach (var p in products) { this.Products.Add(p); } }
private async Task ProcessMessagesProductChangedAsync(Message message, CancellationToken token) { try { ProductChangedMessage productContract = JsonConvert.DeserializeObject <ProductChangedMessage>(Encoding.UTF8.GetString(message.Body)); using (StoreContext context = new StoreContext()) { var _productRepository = new ProductRepository(new StoreContext()); switch (productContract.State) { case ProductState.Deleted: await _productRepository.DeleteAsync(productContract.Product.ToProduct()); break; case ProductState.Modified: await _productRepository.UpsertAsync(productContract.Product.ToProduct()); break; case ProductState.Added: await _productRepository.UpsertAsync(productContract.Product.ToProduct()); break; default: break; } } await _subscriptionClientProductChanged.CompleteAsync(message.SystemProperties.LockToken); } catch (Exception) { throw; } }