public ActionResult Create([Bind(Include = "GRPCODE,PRSCODE,REM,STAMP")] CSGRPPIC cSGRPPIC) { if (ModelState.IsValid) { try { cSGRPPIC.STAMP = 0; db.CSGRPPICs.Add(cSGRPPIC); db.SaveChanges(); return(RedirectToAction("Index")); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { //string message = string.Format("{0}:{1}", // validationErrors.Entry.Entity.ToString(), // validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage); } } } catch (DbUpdateException ex) { UpdateException updateException = (UpdateException)ex.InnerException; if (updateException != null) { if (updateException.InnerException != null) { var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException; foreach (var error in sqlException.Errors) { if (error.Message != null) { ModelState.AddModelError(string.Empty, error.Message); } } } else { ModelState.AddModelError(string.Empty, updateException.Message); } } else { ModelState.AddModelError(string.Empty, updateException.Message); } } } ViewBag.PRSCODE = new SelectList(db.CSPRS, "PRSCODE", "CONSTCODE", cSGRPPIC.PRSCODE); return(View(cSGRPPIC)); }
public ActionResult DeleteConfirmed(string id) { CSGRPPIC cSGRPPIC = db.CSGRPPICs.Find(id); try { db.CSGRPPICs.Remove(cSGRPPIC); db.SaveChanges(); return(RedirectToAction("Index")); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { //string message = string.Format("{0}:{1}", // validationErrors.Entry.Entity.ToString(), // validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage); } } } catch (DbUpdateException ex) { UpdateException updateException = (UpdateException)ex.InnerException; if (updateException != null) { if (updateException.InnerException != null) { var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException; foreach (var error in sqlException.Errors) { if (error.Message != null) { ModelState.AddModelError(string.Empty, error.Message); } } } else { ModelState.AddModelError(string.Empty, updateException.Message); } } else { ModelState.AddModelError(string.Empty, updateException.Message); } } return(View(cSGRPPIC)); }
// GET: CSGRPPICs/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CSGRPPIC cSGRPPIC = db.CSGRPPICs.Find(id); if (cSGRPPIC == null) { return(HttpNotFound()); } return(View(cSGRPPIC)); }
// GET: CSGRPPICs/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CSGRPPIC cSGRPPIC = db.CSGRPPICs.Find(id); if (cSGRPPIC == null) { return(HttpNotFound()); } ViewBag.PRSCODE = new SelectList(db.CSPRS, "PRSCODE", "CONSTCODE", cSGRPPIC.PRSCODE); return(View(cSGRPPIC)); }