public ActionResult Create([Bind(Include = "AccidentTypeId,AccidentTypeTitel")] tbl_AccidentType tbl_AccidentType) { int itemid = 0; if (ModelState.IsValid) { if (Session["OnlineUser"] != null) { if (Session["UserRole"].Equals("SUPERADMIN")) { Random ra = new Random(); itemid = ra.Next(1000, 9999); while (db.tbl_AccidentType.FirstOrDefault(x => x.AccidentTypeId == itemid) != null) { itemid = ra.Next(1000, 9999); } tbl_AccidentType.AccidentTypeId = itemid; db.tbl_AccidentType.Add(tbl_AccidentType); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } } return(View(tbl_AccidentType)); }
// GET: AccidentType/Delete/5 public ActionResult Delete(int?id) { if (Session["OnlineUser"] != null) { if (Session["UserRole"].Equals("SUPERADMIN")) { ViewBag.OnlineUser = Session["UserName"].ToString(); ViewBag.OnlineUserRole = Session["UserRole"].ToString(); if (id == null) { return(RedirectToAction("Err", "Home", new { code = "E-1133", text = "هیچ نوع حادثه ای انتخاب نشده است", url = string.Format("{0}/", RouteData.Values["controller"].ToString()) })); } tbl_AccidentType tbl_AccidentType = db.tbl_AccidentType.Find(id); if (tbl_AccidentType == null) { return(RedirectToAction("Err", "Home", new { code = "E-1133", text = "هیچ حادثه ای باشماره مورد نظر وجود ندارد", url = string.Format("{0}/", RouteData.Values["controller"].ToString()) })); } return(View(tbl_AccidentType)); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } }
public ActionResult Edit([Bind(Include = "AccidentTypeId,AccidentTypeTitel")] tbl_AccidentType tbl_AccidentType) { try { if (ModelState.IsValid) { if (Session["OnlineUser"] != null) { if (Session["UserRole"].Equals("SUPERADMIN")) { db.Entry(tbl_AccidentType).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } } return(View(tbl_AccidentType)); } catch (Exception ex) { ModelState.AddModelError(ex.Message, ex.InnerException.ToString()); return(View()); } }
// GET: AccidentType/Edit/5 public ActionResult Edit(int?id) { try { if (Session["OnlineUser"] != null) { if (Session["UserRole"].Equals("SUPERADMIN")) { if (id == null) { return(RedirectToAction("Err", "Home", new { code = "E-1133", text = "هیچ نوع داده ای انتخاب نشده است", url = string.Format("{0}/", RouteData.Values["controller"].ToString()) })); } tbl_AccidentType tbl_AccidentType = db.tbl_AccidentType.Find(id); if (tbl_AccidentType == null) { return(RedirectToAction("Err", "Home", new { code = "E-1133", text = "هیچ داده ای باشماره مورد نظر وجود ندارد", url = string.Format("{0}/", RouteData.Values["controller"].ToString()) })); } return(View(tbl_AccidentType)); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } } catch (Exception ex) { ModelState.AddModelError(ex.Message, ex.InnerException.ToString()); return(View()); } }
public ActionResult DeleteConfirmed(int id) { try { tbl_AccidentType tbl_AccidentType = db.tbl_AccidentType.Find(id); db.tbl_AccidentType.Remove(tbl_AccidentType); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError(ex.Message, ex.InnerException.ToString()); return(View()); } }
public ActionResult DeleteConfirmed(int id) { try { tbl_AccidentType tbl_AccidentType = db.tbl_AccidentType.Find(id); db.tbl_AccidentType.Remove(tbl_AccidentType); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception) { return(RedirectToAction("Err", "Home", new { code = "E-1133", text = "ارور بررسی نشده", url = string.Format("{0}/", RouteData.Values["controller"].ToString()) })); throw; } }