public ActionResult UpdateRoles(int id, tbPermission[] roles) { string result = ""; var rsp = new AuthorityRepository(); result = rsp.Delete <tbPermission>(p => p.roleID == id); if (!string.IsNullOrEmpty(result)) { return(Json(JSHelper.JsonMessage(result, false), JsonRequestBehavior.AllowGet)); } if (roles != null) { foreach (var item in roles) { item.roleID = id; result = rsp.Inset <tbPermission>(item); if (!string.IsNullOrEmpty(result)) { return(Json(JSHelper.JsonMessage(result, false), JsonRequestBehavior.AllowGet)); } } } return(Json(JSHelper.JsonMessage("操作成功", true), JsonRequestBehavior.AllowGet)); }
public static string Logon(LogonModel logon) { var db = new AuthorityRepository(); tbUser user = db.GetEntitie <tbUser>(p => p.userID == logon.userID); if (user == null) { return(string.Format("登录失败:用户\"{0}\"不存在!", logon.userID)); } if (user.userPassword != logon.userPassword) { return(string.Format("登录失败:输入的密码不正确!")); } var role = db.GetEntitie <tbRole>(p => p.ID == user.roleID); if (role.disabled) { return(string.Format("登录失败:用户\"{0}\"所属的权限组已被停用!", logon.userID)); } user.lastLogIP = logon.logIP; user.lastLogTime = DateTime.Now; user.logTimes = user.logTimes + 1; Account.currentUser = user; db.Update((tbUser)user); return(string.Empty); }
public async Task <ActionResult> Index([Bind(Include = "SelectedAuthorityId")] ResultsViewModel model) { var language = ControllerContext.RouteData.Values["language"].ToString(); //escape default select 'select authority' option if (model.SelectedAuthorityId != 0) { //Get language enabled rating names var ratingKeys = await RatingKeyRepository.GetRatingKeys(ApiConstant.RatingsUri, language); //Get establishment API query string var queryString = new Dictionary <string, string> { { ApiConstant.QueryStringKeyLocalAuthority, model.SelectedAuthorityId.ToString() } }; //Get establishment model.Ratings = await EstablishmentRepository.GetRating(ApiConstant.EstablishmentUri, queryString, ratingKeys.RatingKeys.ToDictionary(x => x.RatingKey, x => x.RatingName), language); } var authorities = await AuthorityRepository.GetAuthorities(ApiConstant.AuthorityUri, language); ViewBag.AuthorityList = new SelectList(authorities.Authorities.OrderBy(x => x.RegionName).ThenBy(x => x.Name), "Id", "Name", "RegionName", model.SelectedAuthorityId); ViewBag.Language = language ?? "English"; return(View(model)); }
public JsonResult Menu() { UserInfo sysUser = CacheInit.GetUserInfo(HttpContext); AuthorityRepository rep = new AuthorityRepository(); DataTable dt = rep.GetUserMenu(sysUser.UserId); for (int i = 0; i < dt.Rows.Count; i++) { string urls = DataConvert.ToString(dt.Rows[i]["url"]); if (urls != "") { string[] url = urls.Split('/'); string urlmenu = Url.Action(url[3], url[2], new { Area = url[1] }); if (url.Length > 4) { urlmenu = urlmenu + url[4]; } dt.Rows[i]["url"] = urlmenu; } } var rows = DataTable2Object.Data(dt); //var rows = new object[4]; //rows[0] = new { id = 1, cell = new[] { "1", "周报", "", "0", "1", "10", "false", "false" } }; //rows[1] = new { id = 2, cell = new[] { "2", "用户组", "/BusinessCommon/Group/List", "1", "2", "3", "true", "true" } }; //rows[2] = new { id = 3, cell = new[] { "6", "系统", "", "0", "11", "18", "false", "false" } }; //rows[3] = new { id = 4, cell = new[] { "7", "用户", "/BusinessCommon/User/List", "1", "12", "13", "true", "true" } }; var result = new JsonResult(); result.JsonRequestBehavior = JsonRequestBehavior.AllowGet; result.Data = new { page = 1, records = rows.Length, rows = rows, total = 1 }; return(result); }
public async Task <ActionResult> Index() { //First get language from route var language = ControllerContext.RouteData.Values["language"].ToString(); //Get list of local authorities var authorities = await AuthorityRepository.GetAuthorities(ApiConstant.AuthorityUri, language); ViewBag.AuthorityList = new SelectList(authorities.Authorities.OrderBy(x => x.RegionName).ThenBy(x => x.Name), "Id", "Name", "RegionName", 0); ViewBag.Language = language ?? "English"; return(View(new ResultsViewModel { Ratings = null })); }
protected virtual DataTable GetAuthorityGridButton(string pageId, string gridId) { UserInfo sysUser = CacheInit.GetUserInfo(HttpContext); AuthorityRepository rep = new AuthorityRepository(); DataTable dt = rep.GetUserGridButton(sysUser.UserId, pageId, gridId); for (int i = 0; i < dt.Rows.Count; i++) { string urls = DataConvert.ToString(dt.Rows[i]["url"]); if (urls != "") { string[] url = urls.Split('/'); dt.Rows[i]["url"] = Url.Action(url[3], url[2], new { Area = url[1] }); } } return(dt); }
public ActionResult UpdateRoles(int id) { var actions = GetAllActionByAssembly(); actions = actions.Distinct(new FastPropertyComparer <ActionPermission>("actionMark")); var rsp = new AuthorityRepository(); foreach (var item in actions) { item.roleID = id; var m = rsp.GetEntitie <tbPermission>( p => p.roleID == id && p.actionName == item.actionName && p.controllerName == item.controllerName); item.isValid = (m != null); } return(base.DataGrid <ActionPermission>(actions.AsQueryable())); }
public static List<SelectListItem> GetRoleGroup(int select = 0, bool hasAll = false) { List<SelectListItem> Items = new List<SelectListItem>(); if (hasAll) Items.Add(new SelectListItem { Text = "全部", Value = "" }); var model = new AuthorityRepository().GetEntities<tbRole>(p=>!p.disabled); foreach (var m in model) { SelectListItem item = new SelectListItem(); item.Text = m.name; item.Value = m.ID.ToString(); item.Selected = (m.ID == select); Items.Add(item); } return Items; }
public async Task Repository_Authority_Get_Return_Authority() { //Mock Api service var api = new Mock <IApi <AuthoritiesViewModel> >(); api.Setup(x => x.GetAsync(string.Empty, string.Empty)).Returns(Task.FromResult(_model)); //Mock ICache for testing var cacheMock = new Mock <ICache>(); cacheMock.Setup(x => x.Get <EstablishmentsViewModel>(It.IsAny <string>())).Returns(new EstablishmentsViewModel()); cacheMock.Setup(x => x.Add(It.IsAny <string>(), It.IsAny <EstablishmentsViewModel>(), It.IsAny <DateTime>())).Verifiable(); var authorityService = new AuthorityRepository(api.Object, cacheMock.Object, new Mock <ILog>().Object); var result = await authorityService.GetAuthorities(string.Empty, string.Empty); Assert.IsNotNull(result); Assert.AreEqual(10, result.Authorities.Count()); }
public ActionResult List(FormCollection fc) { AuthorityRepository rps = new AuthorityRepository(); return(base.DataGrid <tbRole, IBaseTable>(rps)); }