Esempio n. 1
0
        // GET: Admin/ProductDetails/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductDetail productDetail = await _productDetail.GetByIdAsync(id);

            ViewBag.productId = productDetail.Product.ProductID;
            ViewBag.price     = productDetail.Product.Price;
            if (productDetail == null)
            {
                return(HttpNotFound());
            }
            return(View(productDetail));
        }
Esempio n. 2
0
        /// <summary>
        /// the method cencell order
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ActionResult> CencellOrder(int id)
        {
            //update order
            Order orders = await _order.GetByIdAsync(id);

            orders.Status = Status.cancelled;
            await _order.UpdateAsync(orders);

            //update product quantity

            foreach (var orderDetail in orders.OrderDetails)
            {
                ProductDetail productDetail = await _productDetail.GetByIdAsync(orderDetail.ProductDetail.ProductDetailId);

                productDetail.Quantity += orderDetail.Quantity;
                await _productDetail.UpdateAsync(productDetail);
            }

            return(View(orders));
        }
        public async Task <ActionResult> AddToCart(string id)
        {
            var             arr  = id.Split(' ');
            int             id1  = int.Parse(arr[0]);
            int             qty  = int.Parse(arr[1]);
            List <CartItem> cart = Session[Constant.Cart] as List <CartItem> ?? new List <CartItem>();

            CartItem model = new CartItem();

            ProductDetail product = await _productDetail.GetByIdAsync(id1);

            var itemInCart = cart.FirstOrDefault(x => x.ProductDetail.ProductDetailId == id1);

            if (itemInCart == null)
            {
                if (product.Quantity >= qty)
                {
                    cart.Add(new CartItem()
                    {
                        ProductDetail = product,
                        Quantity      = qty,
                    });
                }
                else
                {
                    return(RedirectToAction("_ErrorOrder", new { idQty = id1 + " " + qty }));
                }
            }
            else
            {
                if ((itemInCart.Quantity + qty) <= product.Quantity)
                {
                    itemInCart.Quantity += qty;
                }
                else
                {
                    return(RedirectToAction("_ErrorOrder", new { idQty = id1 + " " + qty + " " + itemInCart.Quantity }));
                }
            }

            int qty1 = 0;

            foreach (var item in cart)
            {
                qty1 += item.Quantity;
            }
            model.Quantity         = qty1;
            Session[Constant.Cart] = cart;

            return(RedirectToAction("CartPartial"));
        }