public JsonResult SaveRoleAccessRight(JsonTreeData objectJson) { try { if (objectJson != null && !String.IsNullOrEmpty(objectJson.NhomNguoiDung)) { SYS_MENU_ROLE_CTRL smrCtrl = new SYS_MENU_ROLE_CTRL(); smrCtrl.DeleteItemByValues("ID_ROLE", objectJson.NhomNguoiDung); if (objectJson.DanhSachQuyen != null) { foreach (JsonNodeList tmpNode in objectJson.DanhSachQuyen) { var tmpRightAccess = tmpNode.data; string strRightAccess = ""; foreach (var prop in tmpRightAccess.GetType().GetProperties()) { var name = prop.Name; var value = prop.GetValue(tmpRightAccess, null); strRightAccess += (value.ToBoolean() == true) ? "1" : "0"; } SYS_MENU_ROLE smrObj = new SYS_MENU_ROLE(); smrObj.ACCESS_RIGHT = strRightAccess; smrObj.ID_ROLE = objectJson.NhomNguoiDung; smrObj.ID_SYS_MENU = tmpNode.id.ToInt32(); smrCtrl.CreateItem(smrObj); } } if (objectJson.DanhSachUndetermineds != null) { foreach (int tmpI in objectJson.DanhSachUndetermineds) { string strRightAccess = "1000000"; SYS_MENU_ROLE smrObj = new SYS_MENU_ROLE(); smrObj.ACCESS_RIGHT = strRightAccess; smrObj.ID_ROLE = objectJson.NhomNguoiDung; smrObj.ID_SYS_MENU = tmpI; smrCtrl.CreateItem(smrObj); } } } return(Json(new { Result = String.Format("Fist item in list: '{0}'", 1) })); } catch (Exception ex) { return(Json(new { Result = "Fail to add" })); } }
public ActionResult GetRoleAccessRight(string roleId, int?isPopup) { try { if (!String.IsNullOrEmpty(roleId)) { var roleManager = HttpContext.GetOwinContext().Get <ApplicationRoleManager>(); ViewBag.NhomNguoiDungKey = roleId; ViewBag.NhomNguoiDungName = roleManager.FindById(roleId).Name.Replace("_" + SysBaseInfor.GetCurrentUnitCode().ToLower() + SysBaseInfor.SignProject, ""); var model = CreateTreeData(); SYS_MENU_ROLE_CTRL smrCtrl = new SYS_MENU_ROLE_CTRL(); var nhomNguoiDungLstRoles = smrCtrl.GetListItemsHaveWhere(String.Format("ID_ROLE = '{0}'", roleId)); foreach (SYS_MENU_ROLE tmpSmr in nhomNguoiDungLstRoles) { JsTreeModel tmpNode = FindNodeInTree(model, tmpSmr.ID_SYS_MENU); if (tmpNode != null && (tmpNode.children == null || tmpNode.children.Count == 0)) { tmpNode.data = new { quyenXem = (tmpSmr.ACCESS_RIGHT[0] == '1') ? true : false, quyenThemMoi = (tmpSmr.ACCESS_RIGHT[1] == '1') ? true : false, quyenSua = (tmpSmr.ACCESS_RIGHT[2] == '1') ? true : false, quyenXoa = (tmpSmr.ACCESS_RIGHT[3] == '1') ? true : false, quyenChuyen = (tmpSmr.ACCESS_RIGHT[4] == '1') ? true : false, quyenDuyet = (tmpSmr.ACCESS_RIGHT[5] == '1') ? true : false, quyenXuatBan = (tmpSmr.ACCESS_RIGHT[6] == '1') ? true : false }; tmpNode.state = new { opened = true, @checked = true }; } } if (isPopup > 0) { return(PartialView("~/Views/SysMenuManage/_ModalTreeRightSelect.cshtml", model)); } else { return(PartialView("~/Views/SysMenuManage/_TreeRightSelect.cshtml", model)); } } return(PartialView(blankViewUrl)); } catch (Exception ex) { return(PartialView(blankViewUrl)); } }
public async Task <bool> OnLogin() { string userNameForauthen = Session["userLogin"].ToString(); string unitNameForauthen = Session["unitLogin"].ToString(); UnitsDAL unitCtrl = new UnitsDAL(); Units unitObj = unitCtrl.GetUnitByCode(unitNameForauthen); try { var userManager = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>(); var roleManager = System.Web.HttpContext.Current.GetOwinContext().Get <ApplicationRoleManager>(); ApplicationUser user = userManager.FindByName(userNameForauthen); if (user != null) { SysBaseInfor.SetCurrentUserName(user.UserName); SysBaseInfor.SetCurrentUserDisplayName(user.DisplayName); SysBaseInfor.SetCurrentUserId(user.Id); SysBaseInfor.SetCurrentUserType(user.Type); SysBaseInfor.SetCurrentUserTypeInfo(user.TypeInfo); SysBaseInfor.SetIdNguoiDung(user.TypeInfo.ToString()); SysBaseInfor.SetCurrentUnitId(unitObj.Id); SysBaseInfor.SetCurrentUnitCode(unitObj.Code); SysBaseInfor.SetCurrentUnitName(unitObj.Name); SysBaseInfor.SetCurrentMediaURL(unitObj.MediaUrl); SysBaseInfor.SetCurrentUnitLogoUrl(unitObj.LogoUrl); var lstRoleNames = userManager.GetRoles(user.Id); if (lstRoleNames.Count > 0) { SYS_MENU_ROLE_CTRL smrCtrl = new SYS_MENU_ROLE_CTRL(); var tmpLstRoles = new List <SYS_MENU_ROLE>(); foreach (string tmpRoleName in lstRoleNames) { if (!string.IsNullOrEmpty(tmpRoleName)) { var tmpRole = roleManager.FindByName(tmpRoleName); var lstRoles = smrCtrl.GetLstSysMenuRoleWithView(tmpRole.Id); foreach (SYS_MENU_ROLE tmpSmr in lstRoles) { if (tmpSmr.ID > 0) { if (tmpLstRoles.All(r => r.ID_SYS_MENU != tmpSmr.ID_SYS_MENU)) { tmpLstRoles.Add(tmpSmr); } else { var index = tmpLstRoles.FindIndex(r => r.ID_SYS_MENU == tmpSmr.ID_SYS_MENU); var tmpAccessOld = tmpLstRoles[index].ACCESS_RIGHT; var tmpAccessNew = tmpSmr.ACCESS_RIGHT; var tmpAccessJoin = ""; if (tmpAccessOld != tmpAccessNew) { for (int i = 0; i < tmpAccessOld.Length; i++) { tmpAccessJoin += (tmpAccessOld[i] > tmpAccessNew[i]) ? tmpAccessOld[i] : tmpAccessNew[i]; } tmpLstRoles[index].ACCESS_RIGHT = tmpAccessJoin; } } } } } } var jsonLstRoles = JsonConvert.SerializeObject(tmpLstRoles); SysBaseInfor.SetCurrentUserListMenu(jsonLstRoles); } var sign = await SignInHelper.SignInOrTwoFactor(user, true); } } catch (Exception ex) { //AuthenticationManager.SignOut(); //Session.Abandon(); //ModelState.AddModelError("", ex); //return View(model); return(false); } return(true); }