public async void AddItem(Item item) { if (User.userCart.cartItems == null) { User.userCart.cartItems = new Dictionary <int, int>(); } if (!User.userCart.cartItems.ContainsKey(item.id)) { User.userCart.cartItems[item.id] = 0; } User.userCart.cartItems[item.id]++; await UserCartDataAccess.UpdateAsync(User.userCart); }
public async void BuyCart() { // calculate cart cost double cartCost = 0; foreach (var kv in User.userCart.cartItems) { cartCost += ItemDataAccess.GetAsync(kv.Key).Result.cost *kv.Value; } Clear(); User.balance -= cartCost; await UserCartDataAccess.UpdateAsync(User.userCart); await UserDataAccess.UpdateAsync(new UserUpdateModel(User)); }
public async void Clear() { User.userCart.cartItems.Clear(); User.userCart.choosenBonus = null; await UserCartDataAccess.UpdateAsync(User.userCart); }