/// <summary>
        /// The add to cart.
        /// </summary>
        /// <param name="id">
        /// The id.
        /// </param>
        public void AddToCart(int id)
        {
            // Retrieve the product from the database.
            this.ShoppingCartId = this.GetCartId();

            var currentList = GetCartItems();
            var cartItem = currentList.SingleOrDefault(
                c => c.CartId == this.ShoppingCartId
               && c.Product.Id == id);

            if (cartItem == null)
            {
                // Create a new cart item if no cart item exists.
                cartItem = new CartItem
                {
                    Pk = id + 1,
                    ProductId = id,
                    CartId = this.ShoppingCartId,
                    Product = this._db.GetById(id),
                    Quantity = 1,
                    DateCreated = DateTime.Now
                };

                this._db.ShoppingCartItems.Add(cartItem);
            }
            else
            {
                // If the item does exist in the cart,
                // then add one to the quantity.
                cartItem.Quantity++;
            }

            this._db.SaveChanges();
        }
 /// <summary>
 /// The get car item from record.
 /// </summary>
 /// <param name="record">
 /// The record.
 /// </param>
 /// <returns>
 /// The <see cref="CartItem"/>.
 /// </returns>
 protected CartItem GetCarItemFromRecord(List<string> record)
 {
     if (record == null) return null;
     var caritem = new CartItem();
     caritem.Product = new ArticleLogic(new ArticleOracleContext(), new BrandOracleContext(), new CategoryOracleContext(), new SpecificationOracleContext()).GetById(Convert.ToInt32(record[1]));
     caritem.ProductId = Convert.ToInt32(record[1]);
     caritem.Quantity = Convert.ToInt32(record[2]);
     return caritem;
 }
 /// <summary>
 /// The insert order article.
 /// </summary>
 /// <param name="caritem">
 /// The caritem.
 /// </param>
 /// <param name="order">
 /// The order.
 /// </param>
 public void InsertOrderArticle(CartItem caritem, Order order)
 {
     var query =
         "INSERT INTO artikel_factuur (ordernummer, artikelnummer, aantal) VALUES (:ordernummer, :artikelnummer, :aantal)";
     var parameters = new List<OracleParameter>
     {
         new OracleParameter("ordernummer", order.Id),
         new OracleParameter("artikelnummer", caritem.Product.Id),
         new OracleParameter("aantal", caritem.Quantity)
     };
     Database.ExecuteNonQuery(query,parameters);
 }
Пример #4
0
 /// <summary>
 /// The insert order article.
 /// </summary>
 /// <param name="caritem">
 /// The caritem.
 /// </param>
 /// <param name="order">
 /// The order.
 /// </param>
 public void InsertOrderArticle(CartItem caritem, Order order)
 {
     this._context.InsertOrderArticle(caritem, order);
 }