Example #1
0
        public void AddToCart(Product p)
        {
            bool alreadyInCart = false;

            foreach (CartItem item in CartItems)
            {
                if (item.product.id == p.id)
                {
                    item.quantity++;
                    alreadyInCart = true;
                    break;
                }
            }

            if(!alreadyInCart)
            {
                this.CartItems.Add(new CartItem(p, 1));
            }
        }
Example #2
0
 public CartItem(Product p, int quantity = 1)
 {
     this.quantity = quantity;
     this.product = p;
 }
Example #3
0
        public Product getProduct(int product_id)
        {
            String query = "SELECT * FROM products, categories WHERE products.category=categories.id AND products.id=@id";
            Product p = null;

            using (SqlCommand cmd = new SqlCommand(query, connection))
            {
                cmd.Parameters.AddWithValue("@id", product_id);
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    int id = Convert.ToInt32(reader["id"]);
                    String name = Convert.ToString(reader["name"]);
                    String image_path = Convert.ToString(reader["image_path"]);
                    String description = Convert.ToString(reader["description"]);
                    int ram_amount = Convert.ToInt16(reader["ram_amount"]);
                    String ram_type = Convert.ToString(reader["ram_type"]);
                    Double cpu_freq = Convert.ToDouble(reader["cpu_freq"]);
                    String cpu_brand = Convert.ToString(reader["cpu_brand"]);
                    int hdd_amount = Convert.ToInt32(reader["hdd_amount"]);
                    String hdd_brand = Convert.ToString(reader["hdd_brand"]);
                    String gpu = Convert.ToString(reader["gpu"]);
                    int display = Convert.ToInt16(reader["display"]);
                    int category = Convert.ToInt32(reader["category"]);
                    String cat_name = Convert.ToString(reader["cat_name"]);
                    Double price = Convert.ToDouble(reader["price"]);
                    var discount = reader["discount"] as string;

                    int i = 0;
                    if ( ! string.IsNullOrWhiteSpace(Convert.ToString(discount)))
                    {

                        i = Convert.ToInt32(discount);
                    }
                    p = new Product(
                            id, name, image_path, description, ram_amount, ram_type, cpu_freq, cpu_brand, hdd_amount, hdd_brand, gpu, display, cat_name, price, i
                        );
                }
                reader.Close();
            }
            return p;
        }
Example #4
0
 public void AddToCart(Product p, int quantity)
 {
     this.CartItems.Add(new CartItem(p, quantity));
 }