public ActionResult InputMOTDetails(tblMOT model, int?id) { if (ModelState.IsValid) { if (id > 0) { var cm = db.tblMOT.Where(x => x.ID == id).FirstOrDefault(); cm.ID = Convert.ToInt32(id); cm.Name = model.Name; db.Entry(cm).State = EntityState.Modified; db.SaveChanges(); ModelState.Clear(); TempData["msg"] = "Update Succussfully"; return(RedirectToAction("MOTDetails")); } else { model.Status = true; db.tblMOT.Add(model); db.SaveChanges(); ModelState.Clear(); TempData["msg"] = "Created Sucessfully!"; return(RedirectToAction("MOTDetails")); } } return(View()); }
public ActionResult InputMOTDetails(int?id, string E) { if (id > 0 && E == "D") { tblMOT model = db.tblMOT.Find(id); db.Entry(model).State = EntityState.Deleted; db.SaveChanges(); TempData["msg"] = "Deleted Sucessfully!"; return(RedirectToAction("MOTDetails")); } else if (id > 0) { tblMOT model = db.tblMOT.Find(id); return(View(model)); } return(View()); }