public ActionResult Create(Application app) { app.Date = DateTime.Now; try { if (ModelState.IsValid) { db.Applications.Add(app); db.Employees.Find(Session["user"]).Applications.Add(app); db.SaveChanges(); //File(app.ApplicationId); return RedirectToAction("Details/" + app.ApplicationId, "Application"); } } catch (DataException) { //Log the error (add a variable name after DataException) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return View(app); }
public ActionResult Edit(Application app) { app.Date = DateTime.Now; try { if (ModelState.IsValid) { db.Entry(app).State = EntityState.Modified; db.SaveChanges(); File(app.ApplicationId); return RedirectToAction("Details/" + app.ApplicationId, "Application"); } } catch (DataException) { //Log the error (add a variable name after DataException) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return View(app); }