Exemplo n.º 1
0
        public ActionResult PurchaseHistory(ViewAllProductModel model)
        {
            try
            {
                if (Session["accountID"] != null)
                {
                    List<Order> orderList = new OrderClient().GetBoughtOrdersByAccountID((int)Session["accountID"]).ToList();

                    foreach (Order o in orderList)
                    {
                        List<ProductOrder> productOrderlist = new OrderClient().GetProductOrderByOrderID(o.ID).ToList();

                        foreach (ProductOrder po in productOrderlist)
                        {
                            allPO.Add(po);
                        }
                    }
                    return View("PurchaseHistory", allPO);
                }
                else
                {
                    return RedirectToAction("Login", "Login");
                }
            }
            catch (Exception e)
            {
                ViewBag.Error = "An error has occured.";
                return View("PurchaseHistory", new List<ProductOrder>());
            }
        }
Exemplo n.º 2
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;
                    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");
        }
Exemplo n.º 3
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");
        }
Exemplo n.º 4
0
        public ActionResult Details(int id)
        {
            double rating = new ProductClient().GetRatingsByProduct(id);

            Product pro = new ProductClient().GetProductByID(id);
            ViewAllProductModel m = new ViewAllProductModel();
            m.myProduct = pro;
            m.rating = rating;
            return View(m);
        }
Exemplo n.º 5
0
 public ActionResult Details(int id)
 {
     Product pro = new ProductClient().GetProductByID(id);
     ViewAllProductModel m = new ViewAllProductModel();
     m.myProduct = pro;
     return View(m);
 }