public void Add(FoodItem item) { Items = Items ?? new List <FoodItem>(); Items.Add(item); CartUpdated?.Invoke(item, Items.Sum(i => i.Price)); }
public async Task ClearAsync() { await shoppingCartClient.ClearShoppingCartAsync(); items.Clear(); CartUpdated?.Invoke(this, EventArgs.Empty); }
public async Task RemoveItemAsync(int itemId) { await shoppingCartClient.RemoveShoppingCartItemAsync(itemId); ShoppingCartItem?item = items.FirstOrDefault(i => i.Id == itemId); if (item != null) { items.Remove(item); } CartUpdated?.Invoke(this, EventArgs.Empty); }
public async Task InitializeAsync() { ShoppingCart?cart = await shoppingCartClient.GetShoppingCartAsync(); items.Clear(); foreach (ShoppingCartItem?item in cart.Items) { items.Add(item); } CartUpdated?.Invoke(this, EventArgs.Empty); }
public async Task UpdateItemQuantityAsync(int itemId, int quantity) { await shoppingCartClient.UpdateItemQuantityAsync(itemId, quantity); ShoppingCartItem?item = items.FirstOrDefault(i => i.Id == itemId); if (item != null) { if (quantity == 0) { items.Remove(item); } else { item.Quantity = quantity; } } CartUpdated?.Invoke(this, EventArgs.Empty); }
public async Task AddItemAsync(int?productId, int?productVariantId, int?offerId, int?priceId, int quantity = 1) { if (quantity <= 0) { throw new ArgumentOutOfRangeException(nameof(quantity)); } ShoppingCartItem?item = await shoppingCartClient.AddShoppingCartItemAsync(productId, productVariantId, offerId, priceId, quantity); ShoppingCartItem?item2 = items.FirstOrDefault(i => i.Id == item.Id); if (item2 == null) { items.Add(item); } else { int index = items.TakeWhile(i => i.Id != item.Id).Count(); items[index] = item; } CartUpdated?.Invoke(this, EventArgs.Empty); }
public void Clear() { Items?.Clear(); CartUpdated?.Invoke(null, 0); }
public void Remove(FoodItem item) { Items?.Remove(item); CartUpdated?.Invoke(item, Items.Sum(i => i.Price)); }
private void OnCartUpdated() { CartUpdated?.Invoke(this, EventArgs.Empty); }
public void NotifyCartUpdated() => CartUpdated?.Invoke();