public ActionResult Edit([Bind(Include = "Id,Name")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult EditCart(FormCollection collection) { MVCTestEntities _entity = new MVCTestEntities(); Cart ct = new Cart(); ct.CartID = Convert.ToInt32(collection["CartID"]); ct.ProductQnt = Convert.ToInt32(collection["ProductQnt"]); ct.TotalPrice = Convert.ToInt32(collection["ProductQnt"]) * Convert.ToInt32(collection["UnitPrice"]); // update cart _entity.Carts.Attach(ct); var et = _entity.Entry(ct); et.Property(e => e.ProductQnt).IsModified = true; et.Property(e => e.TotalPrice).IsModified = true; _entity.SaveChanges(); var lst1 = (from mc in _entity.Carts join pr in _entity.Products on mc.ProductID equals pr.ProductID join ur in _entity.Users on mc.UserID equals ur.UserID where mc.CartID == ct.CartID select new { ProductName = pr.Name, ProductImage = pr.ImagePath, ProductQnt = mc.ProductQnt, TotalPrice = mc.TotalPrice, CartID = mc.CartID }).ToList(); List <MyCart> mcrt = new List <MyCart>(); for (int j = 0; j < lst1.Count; j++) { MyCart mct = new MyCart(); mct.ProductName = lst1[j].ProductName; mct.ProductQnt = lst1[j].ProductQnt; mct.TotalPrice = lst1[j].TotalPrice; mct.CartID = lst1[j].CartID; mct.ProductImage = lst1[j].ProductImage; mcrt.Add(mct); } Session["Result"] = mcrt; ViewBag.Myorder = mcrt; return(View("MyCart", mcrt)); }