public override async Task <TrackProductResponse> TrackProduct(TrackProductRequest request, ServerCallContext context) { try { var product = await _productLoaderService.LoadProductAsync(request.ProductUrl); if (product != null) { var savedProduct = await _productsService.AddOrUpdateProductAsync(product); if (savedProduct != null) { var productResponse = new TrackProductResponse { Description = savedProduct.Description, Discount = savedProduct.Discount, Id = (int)savedProduct.Id, ImageUrl = savedProduct.ImageUrl, Price = (float)savedProduct.Price, Title = savedProduct.Title, Url = savedProduct.Href, SellStatus = savedProduct.SellStatus, Status = savedProduct.Status, PrevPrice = (float)(savedProduct.PriceHistory?.OrderByDescending(x => x.LastUpdated).FirstOrDefault()?.Price ?? savedProduct.Price) }; productResponse.AdditionalPrices.AddRange(savedProduct.AdditionalPrices.Select(x => new ProductAdditionalPricesResponse { Description = x.Description, DiscountPrice = (float)x.DiscountPrice, Id = x.Id, LastUpdatedOn = Timestamp.FromDateTime(x.LastUpdated), ProductId = x.ProductId, Title = x.Title })); return(productResponse); } } } catch (Exception ex) { _logger.LogError($"An error has occurred when trying to add product for price tracking. {ex}"); } return(null); }