/// <summary> /// 更新用户所属角色 /// </summary> /// <returns></returns> public ActionResult UpdateUserRole() { try { if (Session["User"] == null) { throw new Exception("你还未登录,请重新登录。"); } //if (string.IsNullOrEmpty(userID)) throw new Exception("用户ID不能为空。"); UserDbContext uc = new UserDbContext("ConnStr1"); List <Roles> datas = uc.GetRoles(string.Empty, true); if (datas != null) { return(View(datas)); } else { return(View(new List <Roles>())); } } catch (Exception ex) { if (ex.Message != null) { } this.ViewBag.ErrMsg = MisBase.BaseUT.GetRootException(ex).Message; string script = MvcUT.ShowAlertAndHref(this, ex.Message, "Index"); return(Content(script)); } }
public ActionResult Login(Users data) { try { UserDbContext uc = new UserDbContext("ConnStr1"); Users user = uc.Login(data.UserAccount, data.UserPwd, Enum_LoginMethod.UserAccount); string tickStr = string.Empty; if (user != null) { tickStr = "登录成功。"; SessionManager.User = user; SessionManager.UserName = user.UserName; SessionManager.UserID = user.UserID; string script = MvcUT.Href(this, "Index", null); return(Content(script)); } else { SessionManager.User = null; SessionManager.UserName = string.Empty; SessionManager.UserID = string.Empty; tickStr = "登录失败,请检查账户与密码是否有误?"; string script = MvcUT.ShowAlertAndHref(this, tickStr, "Login", null); return(Content(script)); } } catch (Exception ex) { if (ex.Message != null) { } this.ViewBag.ErrMsg = MisBase.BaseUT.GetRootException(ex).Message; return(View(data)); } }
public ActionResult UpdateRole(Roles data, string updateType) { if (string.IsNullOrEmpty(updateType)) { updateType = "1"; } UserDbContext uc = new UserDbContext("ConnStr1"); try { switch (updateType) { case "1": if (data != null) { data = uc.AddRole(data); uc.SaveChanges(); } else { data = new Roles(); } break; case "2": if (data == null) { throw new Exception("数据为空,无法更新。"); } uc.ModifyRole(data); uc.SaveChanges(); break; case "3": if (data == null) { throw new Exception("数据为空,无法删除。"); } uc.DeleteRole(data); uc.SaveChanges(); break; default: throw new Exception("更新类型出错。"); } //return View(data); //var script = String.Format("<script>alert('更新成功!');location.href='{0}';</script>", Url.Action("UpdateRole")); string script = MvcUT.ShowAlertAndHref(this, "更新成功", "UpdateRole", new { updateType = 2, id = data.RoleID }); return(Content(script, "text/html")); } catch (Exception ex) { if (ex.Message != null) { } this.ViewBag.ErrMsg = MisBase.BaseUT.GetRootException(ex).Message; return(View(data)); } }
public ActionResult UpdateUser(UserRegister data, string updateType) { if (string.IsNullOrEmpty(updateType)) { updateType = "1"; } UserDbContext uc = new UserDbContext("ConnStr1"); Users data2 = null; try { switch (updateType) { case "1": if (data != null) { data2 = (Users)data; data = (UserRegister)uc.AddUser(data2); uc.SaveChanges(); } else { data = new UserRegister(); } break; case "2": if (data == null) { throw new Exception("数据为空,无法更新。"); } uc.ModifyUser(data); uc.SaveChanges(); break; case "3": if (data == null) { throw new Exception("数据为空,无法删除。"); } uc.DeleteUser(data); uc.SaveChanges(); break; default: throw new Exception("更新类型出错。"); } string script = MvcUT.ShowAlertAndHref(this, "更新成功", "UpdateUser"); return(Content(script)); } catch (Exception ex) { if (ex.Message != null) { } this.ViewBag.ErrMsg = MisBase.BaseUT.GetRootException(ex).Message; return(View(data)); } }