public ActionResult CreateProduct(HttpPostedFileBase file, Product model) { SmartNerdDataContext db = new SmartNerdDataContext(); if (file == null || file.ContentLength == 0 || file.ContentType != "image/png") { ModelState.AddModelError("", "Product Image must be a valid PNG"); TempData["ModelState"] = ModelState; } if (ModelState.IsValid) { var prod = new DataModels.Product { Description = model.Description, Inventory = model.Inventory, Name = model.ProductName, Price = model.Price }; db.Products.InsertOnSubmit(prod); db.SubmitChanges(); var path = Path.Combine(Server.MapPath("~/Images/p"), prod.ProductID.ToString() + ".png"); file.SaveAs(path); return(RedirectToAction("Product", new { productID = prod.ProductID })); } return(RedirectToAction("CreateProduct", model)); }
public ActionResult CreateProduct(HttpPostedFileBase file,Product model) { SmartNerdDataContext db = new SmartNerdDataContext(); if(file == null || file.ContentLength == 0 || file.ContentType != "image/png") { ModelState.AddModelError("","Product Image must be a valid PNG"); TempData["ModelState"] = ModelState; } if(ModelState.IsValid) { var prod = new DataModels.Product { Description = model.Description, Inventory = model.Inventory, Name = model.ProductName, Price = model.Price }; db.Products.InsertOnSubmit(prod); db.SubmitChanges(); var path = Path.Combine(Server.MapPath("~/Images/p"),prod.ProductID.ToString() + ".png"); file.SaveAs(path); return RedirectToAction("Product",new { productID = prod.ProductID }); } return RedirectToAction("CreateProduct",model); }
public ActionResult Checkout(Models.CartViewModels.CheckoutPage model) { SmartNerdDataContext _context = new SmartNerdDataContext(); List <DataModels.Product> dataProducts = (from p in _context.Products where Cart.Products.Select(pr => pr.ProductID).Contains(p.ProductID) select p).ToList(); foreach (var p in model.Products) { DataModels.Product dataProduct = dataProducts.First(pr => pr.ProductID == p.ProductID); Cart.Products.Where(prod => prod.ProductID == p.ProductID).ToList().ForEach(prod => prod.Quantity = p.Quantity); foreach (var pr in Cart.Products.Where(prod => prod.Quantity < 1)) { Cart.RemoveProduct(pr.ProductID); } if (dataProduct.Inventory - p.Quantity < 0) { ModelState.AddModelError("", "There isn't sufficient inventory to place this order (" + dataProduct.Name + ": " + dataProduct.Inventory + ")."); Models.CartViewModels.CheckoutPage c = new Models.CartViewModels.CheckoutPage { Products = (from op in Cart.Products join pro in _context.Products on op.ProductID equals pro.ProductID select new Models.Menu.Product { ProductID = pro.ProductID, ProductName = pro.Name, Quantity = op.Quantity, Description = pro.Description, Price = pro.Price }).ToList(), Total = Cart.Total }; return(View(c)); } } Cart.Save(); return(RedirectToAction("Address", "Cart")); }
public ActionResult Pay(Models.CartViewModels.PayPage model) { if (ModelState.IsValid) { if (Cart.Products == null || Cart.Products.Count == 0) { return(RedirectToAction("Index", "Home")); } if (Cart.OrderID == 0) { return(RedirectToAction("Index", "Home")); } SmartNerdDataContext _context = new SmartNerdDataContext(); List <DataModels.Product> dataProducts = (from p in _context.Products where Cart.Products.Select(pr => pr.ProductID).Contains(p.ProductID) select p).ToList(); foreach (var p in Cart.Products) { DataModels.Product dataProduct = dataProducts.First(pr => pr.ProductID == p.ProductID); if (dataProduct.Inventory - p.Quantity < 0) { ModelState.AddModelError("", "There isn't sufficient inventory to place this order (" + dataProduct.Name + ": " + dataProduct.Inventory + ")."); return(View()); } } Cart.SubmitOrder(new Payment { CardNumber = model.CardNumber, CardType = model.CardType, PayPalID = model.PayPalUsername }); Session["CartID"] = null; return(RedirectToAction("ThankYou", "Cart", new { OrderId = Cart.OrderID })); } return(View()); }