/// <summary> /// Method executed when calling the UnSubscribeProductCommand command, querying the product id to be unsubscribed. /// </summary> /// <param name="link"></param> async void UnSubscribeProduct(string link) { if (!string.IsNullOrWhiteSpace(link)) { var message = await Task.Run(() => _productRepository.UnSubscribeProductsAsync(link)); if (message == "OK") { if (Products != null) { var p = Products.FirstOrDefault(p => p.Link == link); if (p != null) { p.IsSubscribed = false; Products = new ObservableCollection <ProductDto>(Products); } } SubscribeProductCollection.Remove(SubscribeProductCollection.FirstOrDefault(p => p.Link == link)); } } }
/// <summary> /// Method executed when calling the SubscribeProductCommand command to query the product to subscribe to. /// </summary> /// <param name="productDto">productDto as ProductDto</param> async void SubscribeProduct(ProductDto productDto) { if (productDto != null) { Product product = new Product() { Name = productDto.Name, Link = productDto.Link, Image = productDto.Image, Rate = productDto.Rate, Price = productDto.Price }; var message = await Task.Run(() => _productRepository.SubscribeProductAsync(product)); if (message == "OK") { Products.FirstOrDefault(p => p == productDto).IsSubscribed = true; Products = new ObservableCollection <ProductDto>(Products); SubscribeProductCollection.Add(product); } } }