Exemplo n.º 1
0
        public async Task AddItemAsync(string ean)
        {
            var existingRow = Rows.SingleOrDefault(r => r.EAN == ean);

            if (existingRow != null)
            {
                existingRow.Quantity++;
            }
            else
            {
                var cartRow = new CartRow {
                    EAN = ean, Quantity = 1
                };
                _rows.Add(cartRow);
                for (int i = 0; i < 20; i++)
                {
                    try
                    {
                        cartRow.Product = await FetchProductData(ean);

                        break;
                    }
                    catch (RpcException)
                    {
                        await Task.Delay(5000);
                    }
                }
                if (cartRow.Product == null)
                {
                    _rows.Remove(cartRow);
                }
            }
        }
        public async Task AddItemAsync(string ean)
        {
            var existingRow = Rows.SingleOrDefault(r => r.EAN == ean);

            if (existingRow != null)
            {
                // We already have a row for this EAN
                // Just increment the quantity
                existingRow.Quantity++;
            }
            else
            {
                // This is a new EAN
                // First add the row, before the product data is loaded
                var row = new CartRow {
                    EAN = ean, Quantity = 1
                };
                _rows.Add(row);

                // Now fetch
                // Simple retry loop
                for (var i = 0; i < 20; i++)
                {
                    try
                    {
                        row.Product = await FetchProductData(ean);

                        break;
                    }
                    catch (RpcException)
                    {
                        await Task.Delay(5000);
                    }
                }

                if (row.Product == null)
                {
                    // Can't find this product; remove row from cart
                    _rows.Remove(row);
                }
            }
        }