示例#1
0
        public PartialViewResult MostPurchasedItem()
        {
            List<ProductOrder> poList = new ProductClient().GetMostPurchasedItem().ToList();
            Product p;
            ProductOrder po = new ProductOrder();
            foreach (ProductOrder prodOrder in poList)
            {
                po = prodOrder;
            }
            p = new ProductClient().GetProductByID(po.ProductID);

            return PartialView("_mostPurchasedItem", p);
        }
示例#2
0
 /// <summary>
 /// Create a new ProductOrder object.
 /// </summary>
 /// <param name="productID">Initial value of the ProductID property.</param>
 /// <param name="orderID">Initial value of the OrderID property.</param>
 /// <param name="quantity">Initial value of the Quantity property.</param>
 /// <param name="warrantyExpiry">Initial value of the WarrantyExpiry property.</param>
 public static ProductOrder CreateProductOrder(global::System.Int32 productID, global::System.Int32 orderID, global::System.Int32 quantity, global::System.DateTime warrantyExpiry)
 {
     ProductOrder productOrder = new ProductOrder();
     productOrder.ProductID = productID;
     productOrder.OrderID = orderID;
     productOrder.Quantity = quantity;
     productOrder.WarrantyExpiry = warrantyExpiry;
     return productOrder;
 }
示例#3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ProductOrder EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProductOrder(ProductOrder productOrder)
 {
     base.AddObject("ProductOrder", productOrder);
 }
示例#4
0
 public void UpdateProductOrder(ProductOrder po)
 {
     entities.ProductOrder.Attach(GetProductOrderByOrderIDAndProductID(po.OrderID, po.ProductID));
     entities.ProductOrder.ApplyCurrentValues(po);
     entities.SaveChanges();
 }
示例#5
0
 public void AddProductOrder(ProductOrder po)
 {
     entities.ProductOrder.AddObject(po);
     entities.SaveChanges();
 }
        public ActionResult Buy(ViewAllProductModel model)
        {
            OrderStatus os = new OrderClient().GetOrderStatusByName("Cart");
            int accountID = (int)Session["accountID"];

            if (Session["accountID"] != null)
            {
                if (new OrderClient().GetOrderByAccountAndStatus((int)Session["accountID"], os.ID) == null)
                {
                    //Create new Order.

                    DateTime now = DateTime.Today;

                    Order orderToAdd = new Order();
                    orderToAdd.AccountID = accountID;
                    orderToAdd.DateOfOrder = now;
                    orderToAdd.StatusID = os.ID;

                    new OrderClient().AddOrder(orderToAdd);

                    Order order = new OrderClient().GetOrderByAccountAndStatus(accountID, os.ID);
                    int productID = model.myProduct.ID;
                    int quantityToBuy;
                    try
                    {
                         quantityToBuy = Convert.ToInt32(model.quantity);
                    }
                    catch (Exception e)
                    {
                        ViewAllProductModel m = new ViewAllProductModel();
                        m.myProduct = new ProductClient().GetProductByID(model.myProduct.ID);
                        m.rating = new ProductClient().GetRatingsByProduct(model.myProduct.ID);
                        ViewBag.Error = "Please provide a valid quantity amount";
                        return View("Details", m);
                    }

                    if (quantityToBuy <= 0)
                    {
                        ViewAllProductModel m = new ViewAllProductModel();
                        m.myProduct = new ProductClient().GetProductByID(model.myProduct.ID);
                        m.rating = new ProductClient().GetRatingsByProduct(model.myProduct.ID);
                        ViewBag.Error = "Please provide a valid quantity amount";
                        return View("Details", m);
                    }
                    else
                    {
                        ProductOrder po = new ProductOrder();
                        po.ProductID = productID;
                        po.OrderID = order.ID;
                        po.Quantity = quantityToBuy;
                        po.WarrantyExpiry = DateTime.Today.AddYears(2);

                        new OrderClient().AddProductOrder(po);
                    }
                }
                else
                {
                    //Add to current Order.

                    Order order = new OrderClient().GetOrderByAccountAndStatus(accountID, os.ID);
                    int productID = model.myProduct.ID;
                    int quantityToBuy;
                    try
                    {
                        quantityToBuy = Convert.ToInt32(model.quantity);
                    }
                    catch (Exception e)
                    {
                        ViewAllProductModel m = new ViewAllProductModel();
                        m.myProduct = new ProductClient().GetProductByID(model.myProduct.ID);
                        m.rating = new ProductClient().GetRatingsByProduct(model.myProduct.ID);
                        ViewBag.Error = "Please provide a valid quantity amount";
                        return View("Details", m);
                    }

                    if (quantityToBuy <= 0)
                    {
                        ViewAllProductModel m = new ViewAllProductModel();
                        m.myProduct = new ProductClient().GetProductByID(model.myProduct.ID);
                        m.rating = new ProductClient().GetRatingsByProduct(model.myProduct.ID);
                        ViewBag.Error = "Please provide a valid quantity amount";
                        return View("Details", m);
                    }
                    else
                    {
                        ProductOrder po;

                        if (new OrderClient().GetProductOrderByOrderIDAndProductID(order.ID, productID) != null)
                        {
                            po = new OrderClient().GetProductOrderByOrderIDAndProductID(order.ID, productID);
                            po.Quantity = po.Quantity + quantityToBuy;
                            new OrderClient().UpdateProductOrder(po);
                        }
                        else
                        {
                            po = new ProductOrder();
                            po.ProductID = productID;
                            po.OrderID = order.ID;
                            po.Quantity = quantityToBuy;
                            po.WarrantyExpiry = DateTime.Today.AddYears(2);
                            new OrderClient().AddProductOrder(po);
                        }
                    }
                }
            }
            return RedirectToAction("Index", "ShoppingCart");
        }
示例#7
0
        public ActionResult Buy(ViewAllProductModel model)
        {
            OrderStatus os = new OrderClient().GetOrderStatusByName("Cart");
            int accountID = (int)Session["accountID"];

            if (Session["accountID"] != null)
            {
                if (new OrderClient().GetOrderByAccountAndStatus((int)Session["accountID"], os.ID) == null)
                {
                    //Create new Order.

                    DateTime now = DateTime.Today;

                    Order orderToAdd = new Order();
                    orderToAdd.AccountID = accountID;
                    orderToAdd.DateOfOrder = now;
                    orderToAdd.StatusID = os.ID;

                    new OrderClient().AddOrder(orderToAdd);

                    Order order = new OrderClient().GetOrderByAccountAndStatus(accountID, os.ID);
                    int productID = model.myProduct.ID;
                    int quantityToBuy = Convert.ToInt32(model.quantity);

                    ProductOrder po = new ProductOrder();
                    po.ProductID = productID;
                    po.OrderID = order.ID;
                    po.Quantity = quantityToBuy;
                    po.WarrantyExpiry = DateTime.Today.AddYears(2);

                    new OrderClient().AddProductOrder(po);
                }
                else
                {
                    //Add to current Order.

                    Order order = new OrderClient().GetOrderByAccountAndStatus(accountID, os.ID);
                    int productID = model.myProduct.ID;
                    int quantityToBuy = Convert.ToInt32(model.quantity);

                    ProductOrder po;

                    if (new OrderClient().GetProductOrderByOrderIDAndProductID(order.ID, productID) != null)
                    {
                        po = new OrderClient().GetProductOrderByOrderIDAndProductID(order.ID, productID);
                        po.Quantity = po.Quantity + quantityToBuy;
                        new OrderClient().UpdateProductOrder(po);
                    }
                    else
                    {
                        po = new ProductOrder();
                        po.ProductID = productID;
                        po.OrderID = order.ID;
                        po.Quantity = quantityToBuy;
                        po.WarrantyExpiry = DateTime.Today.AddYears(2);
                        new OrderClient().AddProductOrder(po);
                    }
                }
            }

            return RedirectToAction("Index", "ShoppingCart");
        }