protected void Page_Load(object sender, EventArgs e) { int userID = getCurrentUserID(); if (!IsPostBack) { try { using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { bool isAdmin = (bool)cntx.Users.Where(f => f.UserID == userID).Select(f => f.IsAdmin).FirstOrDefault(); if (!isAdmin) { bool haveRights = PortalUtilities.fnHaveRights(userID, Convert.ToInt32(PortalUtilities.MenuLinks.ManageAgentType)); if (!haveRights) { Response.Redirect("~/Admin/"); } } } } catch (Exception) { throw; } //HttpContext.Current("") = userID; //Server.Transfer("TreeLoader.ashx"); // Server.Transfer("AgentType_Handler.ashx?currentUser="******"AgentType_Handler.ashx?currentUser="******"AgentType_Handler.ashx?currentUser=" + userID); } }
protected void Page_Load(object sender, EventArgs e) { int userID = getCurrentUserID(); if (!IsPostBack) { try { using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { bool isAdmin = (bool)cntx.Users.Where(f => f.UserID == userID).Select(f => f.IsAdmin).FirstOrDefault(); if (!isAdmin) { bool haveRights = PortalUtilities.fnHaveRights(userID, Convert.ToInt32(PortalUtilities.MenuLinks.ManageShipper)); if (!haveRights) { Response.Redirect("~/Admin/"); } } } } catch (Exception) { throw; } } }
protected void Page_Load(object sender, EventArgs e) { int userID = getCurrentUserID(); if (!IsPostBack) { using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { bool isAdmin = (bool)cntx.Users.Where(f => f.UserID == userID).Select(f => f.IsAdmin).FirstOrDefault(); if (!isAdmin) { bool haveRights = PortalUtilities.fnHaveRights(userID, Convert.ToInt32(PortalUtilities.MenuLinks.ChangePassword)); if (!haveRights) { Response.Redirect("~/Admin/"); } } var user = cntx.Users.Where(f => f.UserID == userID).Select(f => f.UserName).FirstOrDefault(); if (user == null && user.Equals(null)) { lblUserName.Text = "-- Invalid User --"; btnChangePassword.Enabled = false; txtPassword.Enabled = false; txtConfirmPassword.Enabled = false; } else { lblUserName.Text = user; //txtEmailAddress.Text = user.Email //lblUserRole.Text = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Roles.GetRolesForUser(strUserName)(0)) //strRole = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Roles.GetRolesForUser(strUserName)(0)) //Dim objEmployee = cntx.Employees.Where(Function(f) f.EmployeeID = intEmpID).ToList().FirstOrDefault() //txtEmailAddress.Text = objEmployee.Email } } } }
protected void Page_Load(object sender, EventArgs e) { int userID = getCurrentUserID(); try { if (!IsPostBack) { using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { bool isAdmin = (bool)cntx.Users.Where(f => f.UserID == userID).Select(f => f.IsAdmin).FirstOrDefault(); if (!isAdmin) { bool haveManageUserRights = PortalUtilities.fnHaveRights(userID, Convert.ToInt32(PortalUtilities.MenuLinks.ManageUsers)); bool haveManageRights = PortalUtilities.fnHaveRights(userID, Convert.ToInt32(PortalUtilities.MenuLinks.ManageRights)); bool haveChangePasswordRights = PortalUtilities.fnHaveRights(userID, Convert.ToInt32(PortalUtilities.MenuLinks.ChangePassword)); if (!haveManageUserRights) { divManageUsersDashboard.Visible = false; } if (!haveManageRights) { divManageRightsDashboard.Visible = false; } if (!haveChangePasswordRights) { divChangePasswordDashboard.Visible = false; } } } } } catch (Exception ex) { //lblStatus.Text = ex.Message; } }
protected void rptrMenus_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { int userID = getCurrentUserID(); int intID = (int)DataBinder.Eval(e.Item.DataItem, "MenuID"); Repeater rptrMenuLinks = (Repeater)e.Item.FindControl("rptrMenuLinks"); using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { bool isAdmin = PortalUtilities.isUserAdmin(cntx, userID); if (isAdmin) { Label lblID = (Label)e.Item.FindControl("lblID"); int menuID = Convert.ToInt32(lblID.Text.ToString()); var objMenuLinks = (from ml in cntx.MenuLinks where ml.MenuID == menuID orderby ml.DisplayOrder select new { ml.MenuLinkText, ml.PageURL }).ToList(); rptrMenuLinks.DataSource = objMenuLinks; rptrMenuLinks.DataBind(); } else { var objMenuLinks = (from el in cntx.UserLinks join usr in cntx.Users on el.UserID equals usr.UserID join ml in cntx.MenuLinks on el.MenuLinkID equals ml.MenuLinkID join m in cntx.Menus on ml.MenuID equals m.MenuID where usr.UserID == userID & m.MenuID == intID select new { ml.MenuLinkText, ml.PageURL, ml.DisplayOrder }).Distinct().OrderBy(f => f.DisplayOrder).ToList(); rptrMenuLinks.DataSource = objMenuLinks; rptrMenuLinks.DataBind(); } } } }
protected void grd_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e) { if (e.CommandName == "chngStatus") { try { int RowIndex = int.Parse(e.CommandArgument.ToString()); int UserID = int.Parse(grd.DataKeys[RowIndex]["UserID"].ToString()); string UserName = grd.Rows[RowIndex].Cells[0].Text; using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { //var usr = cntx.Users.Where(f => f.UserName == UserName).Select(f => f.UserName).FirstOrDefault(); var usr = cntx.Users.Find(UserID); if (UserName == "admin") { lblStatus.ForeColor = System.Drawing.Color.Red; lblStatus.Text = "admin user can not be blocked."; } else { usr.IsActive = !usr.IsActive; cntx.SaveChanges(); lblStatus.ForeColor = System.Drawing.Color.DarkGreen; lblStatus.Text = "User status has been updated."; GetUsers(cntx, UserID); } } //MembershipUser usr = Membership.GetUser(UserName); } catch (Exception ex) { lblStatus.ForeColor = System.Drawing.Color.Red; lblStatus.Text = ex.Message; } } else if (e.CommandName == "chngPwd") { try { int RowIndex = int.Parse(e.CommandArgument.ToString()); int UserID = int.Parse(grd.DataKeys[RowIndex]["UserID"].ToString()); string UserName = grd.Rows[RowIndex].Cells[0].Text; //MembershipUser usr = Membership.GetUser(UserName); using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { //var usr = cntx.Users.Where(f => f.UserName == UserName).Select(f => f.UserName).FirstOrDefault(); string newPassword = PortalUtilities.resetPassword(cntx, UserID); } lblStatus.Text = "Password updated with: " + UserName + "@12345"; lblStatus.ForeColor = System.Drawing.Color.DarkGreen; } catch (Exception ex) { lblStatus.ForeColor = System.Drawing.Color.Red; lblStatus.Text = ex.Message; } } }
protected void Page_Load(object sender, EventArgs e) { //if (!string.IsNullOrEmpty(Session["isAdmin"] as string)) //{ // string isAdmin = Session["isAdmin"].ToString(); // if (!isAdmin.Equals("True")) // { // Response.Redirect("~/Account/Login.aspx"); // } //} //else //{ // Response.Redirect("~/Account/Login.aspx"); //} if (!IsPostBack) { Page.Header.DataBind(); int userID = getCurrentUserID(); using (ERP_CMSEntities cntx = new ERP_CMSEntities()) { bool isAdmin = PortalUtilities.isUserAdmin(cntx, userID); if (isAdmin) { var objPanels = (from p in cntx.MenuPanels orderby p.DisplayOrder select new { p.PanelID, p.PanelTitle }).ToList(); rptrMenuPanels.DataSource = objPanels; rptrMenuPanels.DataBind(); } else { var objPanels = (from el in cntx.UserLinks join usr in cntx.Users on el.UserID equals usr.UserID join ml in cntx.MenuLinks on el.MenuLinkID equals ml.MenuLinkID join m in cntx.Menus on ml.MenuID equals m.MenuID join mp in cntx.MenuPanels on m.PanelID equals mp.PanelID where usr.UserID == userID select new { mp.PanelID, mp.PanelTitle, mp.DisplayOrder }).Distinct().OrderBy(f => f.DisplayOrder).ToList(); rptrMenuPanels.DataSource = objPanels; rptrMenuPanels.DataBind(); } bool haveChangePassword = PortalUtilities.fnHaveRights(userID, Convert.ToInt32(PortalUtilities.MenuLinks.ChangePassword)); if (haveChangePassword) { sideMenuLinkPassword.Visible = true; sideMenuDivider.Visible = true; } var objUserRights = cntx.sp_GetPageRightsByUserAndMenuLinkID(userID, Convert.ToInt32(PortalUtilities.MenuLinks.Profile)).Where(f => f.UserRightID > 0).ToList(); IList lstRights = objUserRights.Select(f => f.Title).ToList(); bool haveProfile = PortalUtilities.fnHaveRights(userID, Convert.ToInt32(PortalUtilities.MenuLinks.Profile)); if (objUserRights.Count > 0 && haveProfile == true && (lstRights.Contains("View Self") || lstRights.Contains("Edit Self"))) { sideMenuLinkProfile.Visible = true; sideMenuDivider.Visible = true; } try { var objUser = cntx.Users.Where(f => f.UserID == userID).ToList().FirstOrDefault(); lblLnkSideProfile.Text = objUser.UserName; } catch (Exception) { throw; } } } }