public ActionResult Cart() { Models.CUser User = new Models.CUser(); Models.CProduct product = new Models.CProduct(); Models.CDatabase db = new Models.CDatabase(); User = User.GetCurrentUser(); double dblSubTotal = 0; if (User != null && User.UserID > 0) { User.Cart = db.GetCart(User.UserID); for (int i = 0; i < User.Cart.Count(); i++) { dblSubTotal += User.Cart[i].Price; } User.CartSubTotal = dblSubTotal; } return(View(User)); }
public ActionResult MyProduct() { Models.CUser User = new Models.CUser(); User = User.GetCurrentUser(); if (User.ProductList != null) { User.ProductList.Clear(); } else { User.ProductList = new List <Models.CProduct>(); } Models.CProduct Product = new Models.CProduct(); if (RouteData.Values["id"] != null) { Product = Models.CProduct.GetProduct(Convert.ToInt32(RouteData.Values["id"])); User.ProductList.Add(Product); } else { User.ProductList.Add(Product); } return(View(User)); }
public ActionResult MyProduct(HttpPostedFileBase PrimaryImage, FormCollection Collection) { try { // Cancel if (Collection["btnSubmit"] == "cancel") { return(RedirectToAction("MyProducts")); } Models.CDatabase db = new Models.CDatabase(); Models.CProduct Product = new Models.CProduct(); Models.CUser User = new Models.CUser(); User = User.GetCurrentUser(); Product.ProductID = (Convert.ToInt32(RouteData.Values["id"])); // Delete if (Collection["btnSubmit"] == "delete") { Product.Delete(); return(RedirectToAction("MyProducts")); } if (Collection["btnSubmit"] == "save") { Product.Title = (string)Collection["ProductList[0].Title"]; Product.Price = Convert.ToInt64(Collection["ProductList[0].Price"]); Product.CategoryID = (Models.ProductTypes)Enum.Parse(typeof(Models.ProductTypes), Collection["ProductList[0].CategoryID"].ToString()); Product.Description = (string)Collection["ProductList[0].Description"]; Product.StatusID = Models.StatusTypes.Active; Product.Save(); if (PrimaryImage != null) { Product.PrimaryImage = new Models.CImage(); Product.PrimaryImage.FileName = System.IO.Path.GetFileName(PrimaryImage.FileName); Product.PrimaryImage.FileExtension = System.IO.Path.GetExtension(Product.PrimaryImage.FileName); if (Product.PrimaryImage.IsImageFile()) { Product.PrimaryImage.FileSize = PrimaryImage.ContentLength; Stream stream = PrimaryImage.InputStream; BinaryReader binaryReader = new BinaryReader(stream); Product.PrimaryImage.FileBytes = binaryReader.ReadBytes((int)stream.Length); // If the product already has an image if (db.HasPrimaryImage(Product.ProductID) == true) { // Edit the existing one Product.UpdatePrimaryImage(); } else { // Otherwise, add an image Product.AddPrimaryImage(); } } else { Product.PrimaryImage = null; } } } return(RedirectToAction("MyProducts")); } catch (Exception) { return(null); } }