public ActionResult Create([Bind(Include = "UsageId,UsageTitel,UsageDescription")] tbl_Usage tbl_Usage) { int randm = 0; Random random = new Random(); randm = random.Next(10000, 20000); if (ModelState.IsValid) { if (Session["OnlineUser"] != null) { if (Session["UserRole"].Equals("SUPERADMIN")) { while (db.tbl_Usage.FirstOrDefault(m => m.UsageId == randm) != null) { randm = random.Next(10000, 20000); } tbl_Usage.UsageId = Convert.ToInt32(randm); db.tbl_Usage.Add(tbl_Usage); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } } return(View(tbl_Usage)); }
// GET: Usage/Details/5 public ActionResult Details(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_Usage tbl_Usage = db.tbl_Usage.Find(id); if (tbl_Usage == null) { return(RedirectToAction("Err", "Home", new { code = "E-1133", text = "هیچ نوع کاربری با شناسه وارد شده ثبت نشده است", url = string.Format("{0}/", RouteData.Values["controller"].ToString()) })); } return(View(tbl_Usage)); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } }
// GET: Usage/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(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tbl_Usage tbl_Usage = db.tbl_Usage.Find(id); if (tbl_Usage == null) { return(HttpNotFound()); } return(View(tbl_Usage)); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } }
public ActionResult DeleteConfirmed(int id) { try { if (Session["OnlineUser"] != null) { if (Session["UserRole"].Equals("SUPERADMIN")) { tbl_Usage tbl_Usage = db.tbl_Usage.Find(id); db.tbl_Usage.Remove(tbl_Usage); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } } catch (Exception ex) { ModelState.AddModelError(ex.Message, ex.InnerException.ToString()); return(View()); } }
public ActionResult Edit([Bind(Include = "UsageId,UsageTitel,UsageDescription")] tbl_Usage tbl_Usage) { try { if (ModelState.IsValid) { if (Session["OnlineUser"] != null) { if (Session["UserRole"].Equals("SUPERADMIN")) { db.Entry(tbl_Usage).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } } return(View(tbl_Usage)); } catch (Exception ex) { ModelState.AddModelError(ex.Message, ex.InnerException.ToString()); return(View()); } }
public ActionResult DeleteConfirmed(int id) { if (Session["OnlineUser"] != null) { if (Session["UserRole"].Equals("SUPERADMIN")) { tbl_Usage tbl_Usage = db.tbl_Usage.Find(id); db.tbl_Usage.Remove(tbl_Usage); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } }