Beispiel #1
0
        // Metode der konvertere produktet fra servicen til et produkt som kan anvendes i klienten.
        public CompanyProduct ConvertFromServiceProduct(ProductService.Product productToConvert)
        {
            CompanyProduct convertedProduct = null;

            if (productToConvert != null)
            {
                convertedProduct = new CompanyProduct()
                {
                    Name        = productToConvert.Name,
                    Description = productToConvert.Description,
                    Price       = productToConvert.Price,
                    State       = productToConvert.State,
                    StyleNumber = productToConvert.StyleNumber
                };
                foreach (var prodVer in productToConvert.ProductVersions)
                {
                    CompanyProductVersion convertedProdVer = new CompanyProductVersion()
                    {
                        ColorCode = prodVer.ColorCode,
                        SizeCode  = prodVer.SizeCode,
                        Stock     = prodVer.Stock,
                        Product   = convertedProduct
                    };
                    convertedProduct.ProductVersions.Add(convertedProdVer);
                }
            }
            return(convertedProduct);
        }
 public ActionResult ProductDetail(int id)
 {
     if (id == 0)
     {
         return(HttpNotFound());
     }
     else
     {
         ProductService.Product product = productServ.findById(Convert.ToInt64(id));
         if (product == null)
         {
             return(HttpNotFound());
         }
         return(View(product));
     }
 }
        public PartialViewResult RelatedProducts()
        {
            var  _idRul = Url.RequestContext.RouteData.Values["id"];
            long id     = Convert.ToInt64(_idRul);

            ProductService.Product        CurrentProduct = productServ.findById(id);
            List <ProductService.Product> products       = productServ.findProductsByCategory(Convert.ToInt32(CurrentProduct.Category)).ToList();

            for (int i = 0; i < products.Count; i++)
            {
                if (products[i].id == id)
                {
                    products.RemoveAt(i);
                }
            }
            return(PartialView(products));
        }
        public ActionResult CheckoutDetail(long OrderId)
        {
            ViewBag.OrderId = OrderId;
            long userId = Convert.ToInt64(Session["userid"]);
            List <OrderService.DetailOrder> OrderDetail = OrderSer.findDetailByOrder(OrderId).ToList();
            List <Item> ListItem = new List <Item>();

            foreach (var item in OrderDetail)
            {
                ProductService.Product product = ProductSer.findById(item.ProductId);
                Item newitem = new Item();
                newitem.Pr       = product;
                newitem.Quantity = Convert.ToInt32(item.Quantity);
                ListItem.Add(newitem);
            }
            return(View(ListItem));
        }
 public ActionResult Delete(int id)
 {
     if (id <= 0)
     {
         return(HttpNotFound());
     }
     else
     {
         long ItemId = Convert.ToInt64(id);
         // cart exist
         List <Item>            cart    = (List <Item>)Session["cart"];
         ProductService.Product product = ProServ.findById(ItemId);
         int index = isExisting(ItemId);
         cart.RemoveAt(index);
         Session["cart"] = cart;
         return(Redirect(Request.UrlReferrer.ToString()));
     }
 }
        public ActionResult OrderNow(int id, int quantity = 1)
        {
            if (id <= 0)
            {
                return(HttpNotFound());
            }
            else
            {
                long ItemId = Convert.ToInt64(id);
                //create cart
                if (Session["cart"] == null)
                {
                    List <Item>            cart    = new List <Item>();
                    ProductService.Product product = ProServ.findById(ItemId);
                    cart.Add(new Item(product, quantity));
                    Session["cart"]           = cart;
                    Session["SuccessMessage"] = "Bạn vừa thêm một sản phẩm vào giỏ hàng";
                    return(RedirectToAction("Index", "Cart"));
                }
                else
                {
                    // cart exist
                    List <Item>            cart    = (List <Item>)Session["cart"];
                    ProductService.Product product = ProServ.findById(ItemId);


                    int index = isExisting(ItemId);
                    if (index == -1)
                    {
                        cart.Add(new Item(product, quantity));
                        Session["SuccessMessage"] = "Bạn vừa thêm một sản phẩm vào giỏ hàng";
                    }
                    else
                    {
                        // item exist -> increase quantity
                        cart[index].Quantity      = cart[index].Quantity + quantity;
                        Session["SuccessMessage"] = "Bạn vừa cập nhật một sản phẩm vào giỏ hàng";
                    }

                    Session["cart"] = cart;
                    return(RedirectToAction("Index", "Cart"));
                }
            }
        }
        // chưa viết
        public ActionResult UpdateQuantity(int ProId, int quantity = 1)
        {
            // cart exist
            List <Item> cart = (List <Item>)Session["cart"];

            ProductService.Product product = ProServ.findById(ProId);
            int index = isExisting(ProId);

            if (quantity == 0)
            {
                cart.RemoveAt(index);
                Session["SuccessMessage"] = "Xóa sản phẩm khỏi giỏ hàng thành công!";
            }
            else
            {
                cart.RemoveAt(index);
                cart.Add(new Item(product, quantity));
                Session["cart"]           = cart;
                Session["SuccessMessage"] = "Cập nhật số lượng sản phẩm thành công!";
            }
            return(RedirectToAction("Index", "Cart"));
        }
Beispiel #8
0
 public Item(ProductService.Product product, int quantity)
 {
     this.Pr       = product;
     this.Quantity = quantity;
 }
Beispiel #9
0
 static void DisplayProduct(ProductService.Product product)
 {
     Console.WriteLine("{0} {1} {2}", product.Name, product.Price, product.Category);
 }
Beispiel #10
0
 // GET api/values
 public ProductService.Product GetProduct(int id)
 {
     ProductService.ProductServiceClient client = new ProductService.ProductServiceClient();
     ProductService.Product p = client.GetProductDetails(id);
     return(p);
 }