public ActionResult Buy(int id) { if (Session["cart"] == null) { List <CartItem> Items = new List <CartItem>(); PcComponent cartitem = db.PcComponents.Find(id); Items.Add(new CartItem { PcComponent = cartitem, Quantity = 1 }); Session["cart"] = Items; } else { List <CartItem> Items = (List <CartItem>)Session["cart"]; int index = getIndex(id); if (index != -1) { Items[index].Quantity++; } else { PcComponent cartitem = db.PcComponents.Find(id); Items.Add(new CartItem { PcComponent = cartitem, Quantity = 1 }); } Session["cart"] = Items; } return(RedirectToAction("Index", "PcComponent")); }
public ActionResult DeleteConfirmed(int id) { PcComponent pcComponent = db.PcComponents.Find(id); db.PcComponents.Remove(pcComponent); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ID,Type,Name,Manufacturer,Price,CategoryID")] PcComponent pcComponent) { if (ModelState.IsValid) { db.Entry(pcComponent).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.Categories, "ID", "CategoryName", pcComponent.CategoryID); return(View(pcComponent)); }
// GET: PcComponent/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PcComponent pcComponent = db.PcComponents.Find(id); if (pcComponent == null) { return(HttpNotFound()); } return(View(pcComponent)); }
// GET: PcComponent/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PcComponent pcComponent = db.PcComponents.Find(id); if (pcComponent == null) { return(HttpNotFound()); } ViewBag.CategoryID = new SelectList(db.Categories, "ID", "CategoryName", pcComponent.CategoryID); return(View(pcComponent)); }
// GET: PcComponent/Delete/5 public ActionResult Delete(int?id, bool?saveChangesError = false) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (saveChangesError.GetValueOrDefault()) { ViewBag.ErrorMessage = "Delete failed. Try again, and if the problem persists see your system administrator."; } PcComponent pcComponent = db.PcComponents.Find(id); if (pcComponent == null) { return(HttpNotFound()); } return(View(pcComponent)); }
public ActionResult Create([Bind(Include = "Type,Name,Manufacturer,Price,CategoryID")] PcComponent pcComponent, HttpPostedFileBase file) { try { if (ModelState.IsValid) { byte[] buf = new byte[file.ContentLength]; file.InputStream.Read(buf, 0, buf.Length); pcComponent.Image = buf; db.PcComponents.Add(pcComponent); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } ViewBag.CategoryID = new SelectList(db.Categories, "ID", "CategoryName", pcComponent.CategoryID); return(View(pcComponent)); }