public ActionResult DeleteConfirmed(int id) { try { if (Session["OnlineUser"] != null) { if (Session["UserRole"].Equals("SUPERADMIN")) { tbl_State tbl_State = db.tbl_State.Find(id); db.tbl_State.Remove(tbl_State); 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 Create([Bind(Include = "StateId,StateName,StateAdress,StateTel")] tbl_State tbl_State) { Random ra = new Random(); int rand1 = 0; rand1 = ra.Next(11, 99); if (ModelState.IsValid) { if (Session["OnlineUser"] != null) { if (Session["UserRole"].Equals("SUPERADMIN")) { while (db.tbl_State.FirstOrDefault(m => m.StateId == rand1) != null) { rand1 = ra.Next(11, 99); } tbl_State.StateId = Convert.ToInt32(rand1); db.tbl_State.Add(tbl_State); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } } return(View(tbl_State)); }
public ActionResult Edit([Bind(Include = "StateId,StateName,StateAdress,StateTel")] tbl_State tbl_State) { try { if (ModelState.IsValid) { if (Session["OnlineUser"] != null) { if (Session["UserRole"].Equals("SUPERADMIN")) { db.Entry(tbl_State).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } } return(View(tbl_State)); } catch (Exception ex) { ModelState.AddModelError(ex.Message, ex.InnerException.ToString()); return(View()); } }
// GET: State/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_State tbl_State = db.tbl_State.Find(id); if (tbl_State == null) { return(RedirectToAction("Err", "Home", new { code = "E-1133", text = "هیچ ایستگاهی با شناسه وارد شده ثبت نشده است", url = string.Format("{0}/", RouteData.Values["controller"].ToString()) })); } return(View(tbl_State)); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } }
// GET: State/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_State tbl_State = db.tbl_State.Find(id); if (tbl_State == null) { return(HttpNotFound()); } return(View(tbl_State)); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } }
public StateViewModel AddState(StateViewModel entity) { var data = new tbl_State { StateId = entity.stateId, StateName = entity.stateName, IsActive = entity.isActive, CreatedBy = "admin", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, ModifiedBy = "admin" }; context.tbl_State.Add(data); context.SaveChanges(); return(entity); }
public ActionResult DeleteConfirmed(int id) { if (Session["OnlineUser"] != null) { if (Session["UserRole"].Equals("SUPERADMIN")) { tbl_State tbl_State = db.tbl_State.Find(id); db.tbl_State.Remove(tbl_State); db.SaveChanges(); return(RedirectToAction("Index")); } else { return(RedirectToAction("Accessdenied", "Home")); } } else { return(RedirectToAction("Login", "Account")); } }
public long SaveUpdateState(StateModel model) { ShomaRMEntities db = new ShomaRMEntities(); var userNameExists = db.tbl_State.Where(p => p.ID != model.ID && p.StateName == model.StateName).FirstOrDefault(); if (userNameExists == null) { if (model.ID == 0) { var userData = new tbl_State() { StateName = model.StateName, Abbreviation = model.Abbreviation, }; db.tbl_State.Add(userData); db.SaveChanges(); model.ID = userData.ID; } else { var stateInfo = db.tbl_State.Where(p => p.ID == model.ID).FirstOrDefault(); if (stateInfo != null) { stateInfo.StateName = model.StateName; stateInfo.Abbreviation = model.Abbreviation; db.SaveChanges(); } else { throw new Exception(model.StateName + " not exists in the system."); } } return(model.ID); } else { throw new Exception(model.StateName + " already exists in the system."); } }