public ActionResult Create([Bind(Include = "PRSCODE,CTRYCODE,REGTYPE,REGNO,REM,STAMP")] CSPRSREG cSPRSREG) { if (ModelState.IsValid) { try { cSPRSREG.STAMP = 0; db.CSPRSREGs.Add(cSPRSREG); db.SaveChanges(); return(RedirectToAction("Edit", "CSPRs", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSPRSREG.PRSCODE) })); } 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 = MyHtmlHelpers.ConvertByteStrToId(cSPRSREG.PRSCODE); ViewBag.REGTYPE = new SelectList(db.HKREGTYPEs.Select(x => new { REGTYPE = x.REGTYPE, REGDESC = x.CTRYOPR + " | " + x.REGTYPE }), "REGTYPE", "REGDESC"); ViewBag.CTRYCODE = new SelectList(db.HKCTRies.OrderBy(x => x.CTRYCODE), "CTRYCODE", "CTRYDESC", cSPRSREG.CTRYCODE); return(View(cSPRSREG)); }
// GET: CSPRSREGs/Create public ActionResult Create(string id) { CSPRSREG cSPRSREG = new CSPRSREG(); cSPRSREG.PRSCODE = MyHtmlHelpers.ConvertByteStrToId(id); ViewBag.PRSCODE = cSPRSREG.PRSCODE; ViewBag.CTRYCODE = new SelectList(db.HKCTRies.OrderBy(x => x.CTRYCODE), "CTRYCODE", "CTRYDESC"); ViewBag.REGTYPE = new SelectList(db.HKREGTYPEs.Select(x => new { REGTYPE = x.REGTYPE, REGDESC = x.CTRYOPR + " | " + x.REGTYPE }), "REGTYPE", "REGDESC"); return(View(cSPRSREG)); }
public ActionResult DeleteConfirmed(string id, string ctry, string regtype, string regno) { CSPRSREG cSPRSREG = db.CSPRSREGs.Find(MyHtmlHelpers.ConvertByteStrToId(id), ctry, regtype, regno); try { db.CSPRSREGs.Remove(cSPRSREG); db.SaveChanges(); return(RedirectToAction("Edit", "CSPRs", new { id = id })); } 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 = MyHtmlHelpers.ConvertByteStrToId(id); return(View(cSPRSREG)); }
// GET: CSPRSREGs/Details/5 public ActionResult Details(string id, string ctry, string regtype, string regno) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CSPRSREG cSPRSREG = db.CSPRSREGs.Find(MyHtmlHelpers.ConvertByteStrToId(id), ctry, regtype, regno); if (cSPRSREG == null) { return(HttpNotFound()); } return(View(cSPRSREG)); }
// GET: CSPRSREGs/Edit/5 public ActionResult Edit(string id, string ctry, string regtype, string regno) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CSPRSREG cSPRSREG = db.CSPRSREGs.Find(MyHtmlHelpers.ConvertByteStrToId(id), ctry, regtype, regno); if (cSPRSREG == null) { return(HttpNotFound()); } Session["CSPRSREG_ORIG"] = cSPRSREG; ViewBag.PRSCODE = MyHtmlHelpers.ConvertByteStrToId(id); ViewBag.REGTYPE = new SelectList(db.HKREGTYPEs.Select(x => new { REGTYPE = x.REGTYPE, REGDESC = x.CTRYOPR + " | " + x.REGTYPE }), "REGTYPE", "REGDESC"); ViewBag.CTRYCODE = new SelectList(db.HKCTRies.OrderBy(x => x.CTRYCODE), "CTRYCODE", "CTRYDESC", cSPRSREG.CTRYCODE); return(View(cSPRSREG)); }