/// <summary> /// To be used for in all page_load events of all pages to grant\access action within the page /// to the user. /// </summary> /// <param name="actionName">Name of page's action user wants to perform.</param> /// <returns>True when the page's action is loaded, and false otherwise</returns> /// <remarks>By 'LOAD' i mean set visible to the user</remarks> public static bool LoadActions(string actionName) { // return true; if (LoggedUser == null) { return(false); } Actions dtAction = GIIS.DataLayer.Actions.GetActionsByName(actionName); List <UserRole> dt = UserRole.GetUserRoleListByUserId(LoggedUser.Id); int actionId = 0; if (dtAction == null) { return(false); } else { actionId = dtAction.Id; } foreach (UserRole userrole in dt) { if (RoleAction.Exists(userrole.RoleId, actionId) > 0) { return(true); } } return(false); }
protected void btnAdd_Click(object sender, EventArgs e) { try { if (Page.IsValid) { int userId = CurrentEnvironment.LoggedUser.Id; string machineName = Request.ServerVariables["REMOTE_HOST"].ToString(); int i = 0; if ((lbActions.Items.Count > 0)) { RoleAction o = new RoleAction(); o.RoleId = int.Parse(ddlRole.SelectedValue); for (int j = 0; j <= lbActions.Items.Count - 1; j++) { if (lbActions.Items[j].Selected) { int actionId = int.Parse(lbActions.Items[j].Value.ToString()); if (RoleAction.Exists(o.RoleId, actionId) == 0) { o.ActionId = actionId; o.IsActive = true; i = RoleAction.Insert(o); } } } _actions = Actions.GetLeftActionsOfRole(o.RoleId); BindLeftActionsOfRole(_actions); _roleActions = Actions.GetActionsOfRole(o.RoleId); BindActionsOfRole(_roleActions); } } } catch (Exception ex) { lblSuccess.Visible = false; lblWarning.Visible = false; lblError.Visible = true; } }