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 void Save() { if (!HttpContext.Current.User.IsInRole("Administrator")) { _context.SubmitChanges(); //lets be horribly inefficient and save to the database again //so that we can grab altered product list if it changed decimal total = 0; foreach (OrderProduct p in Products) { total += p.Price * p.Quantity; } _order.OrderTotal = total; _context.SubmitChanges(); } }
public ActionResult RemoveAddress(int addressID, string returnUrl) { SmartNerdDataContext _context = new SmartNerdDataContext(); DataModels.AccountAddress addrs = (from aa in _context.AccountAddresses where aa.UserID == Cart.AccountID.ToString() && aa.AddressID == addressID select aa).First(); _context.AccountAddresses.DeleteOnSubmit(addrs); _context.SubmitChanges(); return(Redirect(returnUrl)); }
public ActionResult Address(Models.CartViewModels.AddressPage model) { if (model.AddressToUse != -1) { Cart.AddressID = model.AddressToUse; Cart.Save(); if (Session["CartID"] == null) { Session["CartID"] = Cart.CartID; } return(RedirectToAction("Pay", "Cart")); } else { TryUpdateModel(model.CartAddress); if (ModelState.IsValid) { Cart.UseNewAddress(new Address { City = model.CartAddress.City, Line1 = model.CartAddress.Line1, Line2 = model.CartAddress.Line2, StateOrProvince = model.CartAddress.StateOrProvince, ZipCode = model.CartAddress.ZipCode, County = model.CartAddress.County, FullName = model.CartAddress.FullName }); if (model.SaveAddress) { DataModels.AccountAddress aa = new DataModels.AccountAddress { UserID = User.Identity.GetUserId(), AddressID = Cart.AddressID.Value, AddressType = "Mailing" }; SmartNerdDataContext _context = new SmartNerdDataContext(); _context.AccountAddresses.InsertOnSubmit(aa); _context.SubmitChanges(); } Cart.Save(); if (Session["CartID"] == null) { Session["CartID"] = Cart.CartID; } return(RedirectToAction("Pay", "Cart")); } } Models.CartViewModels.AddressPage add = BuildAddressPage(); add.CartAddress = model.CartAddress; return(View(add)); }
public ActionResult Product(Product model) { SmartNerdDataContext db = new SmartNerdDataContext(); var prod = db.Products.Single(a => a.ProductID == model.ProductID); prod.Description = model.Description; prod.Name = model.ProductName; prod.Price = model.Price; prod.Inventory = model.Inventory; db.SubmitChanges(); return(View(model)); }
public void UseNewAddress(Address newAddress) { SmartNerdDataContext _context2 = new SmartNerdDataContext(); DataModels.Address _newAddress = new DataModels.Address { FullName = newAddress.FullName, City = newAddress.City, Line1 = newAddress.Line1, Line2 = newAddress.Line2, County = newAddress.County, StateOrProvince = newAddress.StateOrProvince, ZipCode = newAddress.ZipCode, }; _context2.Addresses.InsertOnSubmit(_newAddress); _context2.SubmitChanges(); _order.AddressID = _newAddress.AddressID; }
public ActionResult Address(Models.CartViewModels.AddressPage model) { if(model.AddressToUse != -1) { Cart.AddressID = model.AddressToUse; Cart.Save(); if(Session["CartID"] == null) { Session["CartID"] = Cart.CartID; } return RedirectToAction("Pay","Cart"); } else { TryUpdateModel(model.CartAddress); if(ModelState.IsValid) { Cart.UseNewAddress(new Address { City = model.CartAddress.City, Line1 = model.CartAddress.Line1, Line2 = model.CartAddress.Line2, StateOrProvince = model.CartAddress.StateOrProvince, ZipCode = model.CartAddress.ZipCode, County = model.CartAddress.County, FullName = model.CartAddress.FullName }); if(model.SaveAddress) { DataModels.AccountAddress aa = new DataModels.AccountAddress { UserID = User.Identity.GetUserId(), AddressID = Cart.AddressID.Value, AddressType = "Mailing" }; SmartNerdDataContext _context = new SmartNerdDataContext(); _context.AccountAddresses.InsertOnSubmit(aa); _context.SubmitChanges(); } Cart.Save(); if(Session["CartID"] == null) { Session["CartID"] = Cart.CartID; } return RedirectToAction("Pay","Cart"); } } Models.CartViewModels.AddressPage add = BuildAddressPage(); add.CartAddress = model.CartAddress; return View(add); }
public ActionResult DeleteProduct(Product model) { SmartNerdDataContext db = new SmartNerdDataContext(); var entries = (from a in db.CategoryEntries where a.ProductID == model.ProductID select a).ToList(); foreach (var entry in entries) { db.CategoryEntries.DeleteOnSubmit(entry); } var prod = db.Products.Single(a => a.ProductID == model.ProductID); db.Products.DeleteOnSubmit(prod); db.SubmitChanges(); return(RedirectToAction("Browse")); }
public ActionResult RemoveAddress(int addressID, string returnUrl) { SmartNerdDataContext _context = new SmartNerdDataContext(); DataModels.AccountAddress addrs = (from aa in _context.AccountAddresses where aa.UserID == Cart.AccountID.ToString() && aa.AddressID == addressID select aa).First(); _context.AccountAddresses.DeleteOnSubmit(addrs); _context.SubmitChanges(); return Redirect(returnUrl); }
public ActionResult DeleteProduct(Product model) { SmartNerdDataContext db = new SmartNerdDataContext(); var entries = (from a in db.CategoryEntries where a.ProductID == model.ProductID select a).ToList(); foreach(var entry in entries) db.CategoryEntries.DeleteOnSubmit(entry); var prod = db.Products.Single(a => a.ProductID == model.ProductID); db.Products.DeleteOnSubmit(prod); db.SubmitChanges(); return RedirectToAction("Browse"); }
public ActionResult Product(Product model) { SmartNerdDataContext db = new SmartNerdDataContext(); var prod = db.Products.Single(a => a.ProductID == model.ProductID); prod.Description = model.Description; prod.Name = model.ProductName; prod.Price = model.Price; prod.Inventory = model.Inventory; db.SubmitChanges(); return View(model); }