Ejemplo n.º 1
0
 public ActionResult SaveProduct(FormCollection collection)
 {
     //int productId = int.Parse(collection["ProductID"]);
     //SessionFacade.PRODUCTID = productId;
     ProductModel productToSave = new ProductModel();
     productToSave.Id = int.Parse(collection["Id"]);
     productToSave.Title = collection["Title"];
     productToSave.Available = int.Parse(collection["Available"]);
     productToSave.Price = float.Parse(collection["Price"]);
     productToSave.Image = collection["Image"];
     productToSave.Summary = collection["Summary"];
     productToSave.Details = collection["Details"];
     IBusinessAccount ibac = GenericFactory<ShoppingBusiness, IBusinessAccount>.CreateInstance();
     if (ModelState.IsValid)
     {
         if (ibac.AddProductBussiness(productToSave.Id, productToSave.Title, productToSave.Available, (float)productToSave.Price, productToSave.Image, productToSave.Summary, productToSave.Details))
         {
             return RedirectToAction("Control", "Home");
         }
         else
         {
             ModelState.AddModelError("", "Adding product not successful.");
         }
     }
     return RedirectToAction("Control", "Home");
 }
Ejemplo n.º 2
0
        //Cart
        //display: title summary image price, pcount.
        //Database: join PRODUCT and CART.
        //link: CheckOut
        //DropDown: change count
        //Button: delete item, make editable, save changes
        public ActionResult ViewCart()
        {
            if (SessionFacade.USERNAME == null)
                return RedirectToAction("LogIn", "Home", new { ReturnUrl = "~/Home/ViewCart" });
            else
            {
                ProductModel getCart = new ProductModel();
                float result = 0;
                IBusinessAccount ibac = GenericFactory<ShoppingBusiness, IBusinessAccount>.CreateInstance();
                if (ModelState.IsValid)
                {
                    getCart.ProductTable = ibac.ViewCartBussiness(SessionFacade.EMAIL, ref result);
                    if (getCart.ProductTable.Rows.Count != 0)
                        SessionFacade.TOTAL = float.Parse(getCart.ProductTable.Rows[0][6].ToString());
                    else
                        SessionFacade.TOTAL = 0;
                    if (getCart.ProductTable == null)
                    {
                        ModelState.AddModelError("", "Retrieving products not successful.");
                    }
                }

                // If we got this far, something failed, redisplay form
                return View(getCart);
            }
        }
Ejemplo n.º 3
0
        //Home
        //display: all product name and summary
        //Database: select * from product
        //link: to ShowDetails after each item
        public ActionResult Index()
        {
            //ViewData["Message"] = "欢迎使用 ASP.NET MVC!";
            ProductModel allProducts = new ProductModel();
            IBusinessAccount ibac = GenericFactory<ShoppingBusiness, IBusinessAccount>.CreateInstance();
            if (ModelState.IsValid)
            {
                allProducts.ProductTable = ibac.ViewAllProductBussiness();
                if (allProducts.ProductTable == null)
                {
                    ModelState.AddModelError("", "Retrieving products not successful.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(allProducts);
        }
Ejemplo n.º 4
0
 public ActionResult SaveCart(FormCollection collection)
 {
     ProductModel cartToSave = new ProductModel();
     cartToSave.Id = int.Parse(collection["Id"]);
     cartToSave.Pcount = int.Parse(collection["Pcount"]);
     IBusinessAccount ibac = GenericFactory<ShoppingBusiness, IBusinessAccount>.CreateInstance();
     if (ModelState.IsValid)
     {
         if (ibac.EditCartBussiness(SessionFacade.EMAIL, cartToSave.Id, cartToSave.Pcount))
         {
             return RedirectToAction("ViewCart", "Home");
         }
         else
         {
             ModelState.AddModelError("", "Adding product not successful.");
         }
     }
     return RedirectToAction("ViewCart", "Home");
 }
Ejemplo n.º 5
0
 public ActionResult EditProduct(FormCollection collection)
 {
     if (SessionFacade.USERNAME != "admin")
         return RedirectToAction("LogIn", "Home", new { ReturnUrl = "~/Home/EditProduct" });
     else
     {
         int productId = int.Parse(collection["ProductID"]);
         //SessionFacade.PRODUCTID = productId;
         ProductModel productToEdit = new ProductModel();
         IBusinessAccount ibac = GenericFactory<ShoppingBusiness, IBusinessAccount>.CreateInstance();
         if (ModelState.IsValid)
         {
             productToEdit.ProductTable = ibac.ViewProductBussiness(productId);
             if (productToEdit.ProductTable == null)
             {
                 ModelState.AddModelError("", "Retrieving products not successful.");
             }
             productToEdit.Id = (int)productToEdit.ProductTable.Rows[0][0];
             productToEdit.Title = (string)productToEdit.ProductTable.Rows[0][1];
             productToEdit.Available = (int)productToEdit.ProductTable.Rows[0][2];
             productToEdit.Price = (float)(double)productToEdit.ProductTable.Rows[0][3];
             productToEdit.Image = (string)productToEdit.ProductTable.Rows[0][4];
             productToEdit.Summary = (string)productToEdit.ProductTable.Rows[0][5];
             productToEdit.Details = (string)productToEdit.ProductTable.Rows[0][6];
         }
         return View(productToEdit);
     }
 }
Ejemplo n.º 6
0
 public ActionResult EditCart(FormCollection collection)
 {
     if (SessionFacade.USERNAME == null)
         return RedirectToAction("LogIn", "Home", new { ReturnUrl = "~/Home/EditCart" });
     else
     {
         int productId = int.Parse(collection["ProductID"]);
         //SessionFacade.PRODUCTID = productId;
         ProductModel cartToEdit = new ProductModel();
         float result = 0;
         IBusinessAccount ibac = GenericFactory<ShoppingBusiness, IBusinessAccount>.CreateInstance();
         if (ModelState.IsValid)
         {
             cartToEdit.ProductTable = ibac.ViewCartBussiness(SessionFacade.EMAIL, ref result);
             if (cartToEdit.ProductTable == null)
             {
                 ModelState.AddModelError("", "Retrieving products not successful.");
             }
             cartToEdit.Title = (string)cartToEdit.ProductTable.Rows[0][0];
             cartToEdit.Pcount = (int)cartToEdit.ProductTable.Rows[0][4];
             cartToEdit.Id = productId;
         }
         return View(cartToEdit);
     }
 }
Ejemplo n.º 7
0
        //display: all products in gridview
        //Database: bind db to gridwiew
        //Button: update and delete (for each row)
        //link: direct to AddProduct
        public ActionResult Control()
        {
            if (SessionFacade.USERNAME != "admin")
                return RedirectToAction("LogIn", "Home", new { ReturnUrl = "~/Home/Control" });
            else
            {
                ProductModel allProducts = new ProductModel();
                IBusinessAccount ibac = GenericFactory<ShoppingBusiness, IBusinessAccount>.CreateInstance();
                if (ModelState.IsValid)
                {
                    allProducts.ProductTable = ibac.ViewAllProductBussiness();
                    if (allProducts.ProductTable == null)
                    {
                        ModelState.AddModelError("", "Retrieving products not successful.");
                    }
                }

                // If we got this far, something failed, redisplay form
                return View(allProducts);
            }
        }
Ejemplo n.º 8
0
        //display: cart items, total price
        //link: payment information, direct to CheckOutPayment
        public ActionResult CheckOutView()
        {
            if (SessionFacade.USERNAME == null)
                return RedirectToAction("LogIn", "Home", new { ReturnUrl = "~/Home/CheckOutView" });
            else
            {
                ProductModel getCart = new ProductModel();
                float result = 0;
                IBusinessAccount ibac = GenericFactory<ShoppingBusiness, IBusinessAccount>.CreateInstance();
                if (ModelState.IsValid)
                {
                    getCart.ProductTable = ibac.ViewCartBussiness(SessionFacade.EMAIL, ref result);
                    if (getCart.ProductTable.Rows.Count != 0)
                        SessionFacade.TOTAL = float.Parse(getCart.ProductTable.Rows[0][6].ToString());
                    else
                    {
                        SessionFacade.TOTAL = 0;
                        Response.Write("<script language='javascript'>alert('Please choose you product first!')</script>");
                        Response.Write("<meta http-equiv='refresh' content='0.0;url=Index'>");
                        //return RedirectToAction("Index", "Home");
                        //Thread.Sleep(3);
                    }
                    if (getCart.ProductTable == null)
                    {
                        ModelState.AddModelError("", "Retrieving products not successful.");
                    }
                }

                // If we got this far, something failed, redisplay form
                return View(getCart);
            }
        }
Ejemplo n.º 9
0
        public ActionResult AddProduct(ProductModel model, string returnUrl)
        {
            if (SessionFacade.USERNAME != "admin")
                return RedirectToAction("LogIn", "Home", new { ReturnUrl = "~/Home/AddProduct" });
            else
            {
                IBusinessAccount ibac = GenericFactory<ShoppingBusiness, IBusinessAccount>.CreateInstance();
                if (ModelState.IsValid)
                {
                    if (ibac.AddProductBussiness(model.Id, model.Title, model.Available, (float)model.Price, model.Image, model.Summary, model.Details))
                    {
                        if (!String.IsNullOrEmpty(returnUrl))
                        {
                            return Redirect(returnUrl);
                        }
                        else
                        {
                            //return RedirectToAction("Index");
                            //ViewBag.Message = "Login successful..";
                            return RedirectToAction("Control", "Home");
                            //if (SessionFacade.PAGEREQUESTED != null)
                            //    Response.Redirect(SessionFacade.PAGEREQUESTED);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Adding product not successful.");
                    }
                }

                // If we got this far, something failed, redisplay form
                return View(model);
            }
        }