Example #1
0
        public static Item ToItemDbModel(ItemCartModel itemCartModel)
        {
            var dbModel = new Item {
                Id      = itemCartModel.Id,
                Name    = itemCartModel.Name,
                Price   = itemCartModel.Price,
                Image   = FromBase64String(itemCartModel.ImageUrl),
                InStock = itemCartModel.InStock,
            };

            return(dbModel);
        }
Example #2
0
        public static ItemCartModel ToItemCartModel(Item item)
        {
            var itemModel = new ItemCartModel {
                Id       = item.Id,
                Name     = item.Name,
                Price    = item.Price,
                ImageUrl = null,
                InStock  = item.InStock,
            };

            if (item.Image != null)
            {
                itemModel.ImageUrl = ToBase64String(item.Image);
            }

            return(itemModel);
        }
Example #3
0
        private void AddToCart(object sender, EventArgs e)
        {
            //Send data to cart page
            var selectedDoughItem = PizzaDoughEntry.SelectedItem as PizzaDough;
            var selectedSauceItem = PizzaSauceEntry.SelectedItem as PizzaSauce;
            var connection        = DependencyService.Get <ISQLite>().GetConnection();

            try
            {
                ItemCartModel ItemInCart = new ItemCartModel()
                {
                    CartItemId   = TappedPizzaId,
                    ItemName     = TappedPizzaName,
                    ItemDough    = selectedDoughItem.PizzaDoughName.ToString(),
                    ItemSauce    = selectedSauceItem.PizzaSauceName.ToString(),
                    ItemQuantity = Quantity,
                    ItemPrice    = TappedPizzaPrice
                };
                //Find item in that table created above
                var item = connection.Table <ItemCartModel>().ToList().FirstOrDefault(cartItems => cartItems.ItemId == TappedPizzaId);
                if (item == null)
                {
                    connection.Insert(ItemInCart);
                }
                else
                {
                    item.ItemQuantity += Quantity;
                    connection.Update(item);
                }
                connection.Commit();
                connection.Close();
                DisplayAlert("Cart", "Item added to cart.", "Ok");
                Navigation.PopModalAsync();
            }
            catch (Exception ex)
            {
                DisplayAlert("Error", ex.Message, "Ok");
            }
            finally
            {
                connection.Close();
            }
        }