Beispiel #1
0
 public ActionResult Edit([Bind(Include = "CategoryID,CategoryName")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
 public ActionResult Edit([Bind(Include = "ItemId,ItemName,ItemCategory,ItemAmount,ExpeseDate,CategoryId,UserId")] Item item)
 {
     if (ModelState.IsValid)
     {
         db.Entry(item).State = EntityState.Modified;
         item.UserId          = db.Users.Where(x => x.UserName == User.Identity.Name).FirstOrDefault().UserId;
         item.ItemCategory    = db.Categories.Where(x => x.CategoryID == item.CategoryId).FirstOrDefault().CategoryName;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "CategoryID", "CategoryName", item.CategoryId);
     ViewBag.UserId     = new SelectList(db.Users, "UserId", "UserName", item.UserId);
     return(View(item));
 }