示例#1
0
 public ActionResult EditPurpose(Purpos purpose)
 {
     try
     {
         if (ModelState.IsValid)
         {
             db.Entry(purpose).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("PurposeList"));
         }
         return(View(purpose));
     }
     catch (DbUpdateException uex)
     {
         ViewBag.DbExceptionMessage = ErrorHandler.DbUpdateHandler(uex);
         //ViewBag.DbExceptionMessage = uex.Message;
     }
     catch (SqlException sqlException)
     {
         ViewBag.SqlExceptionMessage = sqlException.Message;
     }
     catch (Exception genericException)
     {
         ViewBag.ExceptionMessage = genericException.Message;
     }
     return(View("~/Views/Errors/Details.cshtml"));
 }
示例#2
0
 public ActionResult DeletePurpose(int?id)
 {
     if (id == 0)
     {
         return(RedirectToAction("PurposeList"));
     }
     try
     {
         Purpos purpose = db.Purposes.SingleOrDefault(c => c.PurposeId == id);
         if (purpose == null)
         {
             return(RedirectToAction("PurposeList"));
         }
         return(View(purpose));
     }
     catch (SqlException sqlException)
     {
         ViewBag.SqlExceptionMessage = sqlException.Message;
     }
     catch (Exception genericException)
     {
         ViewBag.ExceptionMessage = genericException.Message;
     }
     return(View("~/Views/Errors/Details.cshtml"));
 }
示例#3
0
 public ActionResult AddPurpose(Purpos purpose)
 {
     try
     {
         if (ModelState.IsValid)
         {
             Purpos p = new Purpos
             {
                 PurposeId       = purpose.PurposeId,
                 PurposeToCreate = purpose.PurposeToCreate
             };
             db.Purposes.Add(p);
             db.SaveChanges();
             return(RedirectToAction("PurposeList"));
         }
         return(View(purpose));
     }
     catch (DbUpdateException uex)
     {
         ViewBag.DbExceptionMessage = uex.Message;
     }
     catch (Exception ex)
     {
         ViewBag.ExceptionMessage = ex.Message;
     }
     return(View("~/Views/Errors/Details.cshtml"));
 }
示例#4
0
 public ActionResult DeletePurpose(FormCollection form)
 {
     try
     {
         int    id      = Convert.ToInt32(form["PurposeId"]);
         Purpos purpose = db.Purposes.Find(id);
         db.Purposes.Remove(purpose);
         db.SaveChanges();
         return(RedirectToAction("PurposeList"));
     }
     catch (DbUpdateException dbException)
     {
         ViewBag.DbExceptionMessage = ErrorHandler.DbUpdateHandler(dbException);
     }
     catch (SqlException sqlException)
     {
         ViewBag.SqlExceptionMessage = sqlException.Message;
     }
     catch (Exception genericException)
     {
         ViewBag.ExceptionMessage = genericException.Message;
     }
     return(View("~/Views/Errors/Details.cshtml"));
 }