public ActionResult Create([Bind(Include = "GRPCODE,CONO,STAMP")] CSGRPD cSGRPD) { if (ModelState.IsValid) { try { cSGRPD.STAMP = 0; db.CSGRPDs.Add(cSGRPD); db.SaveChanges(); return(RedirectToAction("Index", "CSGRPMs")); } 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.CONO = new SelectList(db.CSCOMSTRs, "CONO", "CONAME", cSGRPD.CONO); return(View(cSGRPD)); }
public ActionResult DeleteConfirmed(string id, string conos) { CSGRPD cSGRPD = db.CSGRPDs.Find(MyHtmlHelpers.ConvertByteStrToId(id), MyHtmlHelpers.ConvertByteStrToId(conos)); try { db.CSGRPDs.Remove(cSGRPD); db.SaveChanges(); return(RedirectToAction("Index", "CSGRPMs")); } 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(cSGRPD)); }
// GET: CSGRPDs/Details/5 public ActionResult Details(string id, string conos) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CSGRPD cSGRPD = db.CSGRPDs.Find(MyHtmlHelpers.ConvertByteStrToId(id), MyHtmlHelpers.ConvertByteStrToId(conos)); if (cSGRPD == null) { return(HttpNotFound()); } ViewBag.CONO = new SelectList(db.CSCOMSTRs.OrderBy(x => x.CONAME), "CONO", "CONAME"); return(View(cSGRPD)); }
public ActionResult Edit([Bind(Include = "GRPCODE,CONO,STAMP")] CSGRPD cSGRPD) { if (ModelState.IsValid) { try { cSGRPD.STAMP = cSGRPD.STAMP + 1; bool changed = false; CSGRPD csOrig = (CSGRPD)Session["CSGRPD_ORIG"]; if (csOrig.CONO != cSGRPD.CONO) { changed = true; } if (changed) { CSGRPD csDel = db.CSGRPDs.Find(csOrig.GRPCODE, csOrig.CONO); db.CSGRPDs.Remove(csDel); db.CSGRPDs.Add(cSGRPD); } else { db.Entry(cSGRPD).State = EntityState.Modified; } db.SaveChanges(); return(RedirectToAction("Index", "CSGRPMs")); } 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.CONO = new SelectList(db.CSCOMSTRs.OrderBy(x => x.CONAME), "CONO", "CONAME", cSGRPD.CONO); return(View(cSGRPD)); }