public ActionResult Create(FormCollection collection) { try { using(var db = new db_Entities()) { var myItem = ToDoViewModel.ToItem(collection); myItem.CreatedOn = DateTime.Now; db.Items.Add(myItem); db.SaveChanges(); return RedirectToAction ("Index", "Home"); } } catch (Exception ex){ throw ex; return View (); } }
public ActionResult Edit(int id, FormCollection collection) { try { using (var db = new db_Entities ()) { Item updatedItem = ToDoViewModel.ToItem(collection); Item myItem = db.Items.FirstOrDefault(i=> i.ItemId == updatedItem.ItemId); if(myItem != null){ myItem.Description = updatedItem.Description; myItem.Name = updatedItem.Name; myItem.CompletedOn = updatedItem.CompletedOn; db.SaveChanges(); } return RedirectToAction ("Index", "Home"); } } catch (Exception ex) { return RedirectToAction ("Index", "Home"); } }