Example #1
0
        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 haveAddUserRights = PortalUtilities.fnHaveRights(userID, Convert.ToInt32(PortalUtilities.MenuLinks.AddUser));
                        var   havePageRights = cntx.sp_GetPageRightsByUserAndMenuLinkID(userID, Convert.ToInt32(PortalUtilities.MenuLinks.ManageUsers)).Where(f => f.UserRightID > 0).ToList();
                        IList listRights     = havePageRights.Select(f => f.Title).ToList();
                        if (havePageRights != null && havePageRights.Count > 0)
                        {
                            if (!listRights.Contains("Add User"))
                            {
                                Response.Redirect("~/Admin/");
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        protected void grdAssignedRights_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            try
            {
                int intUserID = int.Parse(ddlUser.SelectedValue);
                using (ERP_CMSEntities cntx = new ERP_CMSEntities())
                {
                    if (e.Row.RowType == DataControlRowType.DataRow)
                    {
                        // Dim rptInnerRights As Repeater = e.Row.FindControl("rptInnerRights")
                        GridView grdInnerRights = (GridView)e.Row.FindControl("grdAssignedRightsInner");
                        int      intMenuLinkID  = int.Parse(((HiddenField)e.Row.FindControl("hdnMenuLinkID")).Value);
                        var      obj            = cntx.sp_GetPageRightsByUserAndMenuLinkID(intUserID, intMenuLinkID).ToList();
                        if (obj.Count > 0)
                        {
                            // rptInnerRights.DataSource = obj
                            // rptInnerRights.DataBind()
                            grdInnerRights.DataSource = obj;
                            grdInnerRights.DataBind();

                            foreach (GridViewRow row in grdInnerRights.Rows)
                            {
                                CheckBox chkInner             = (CheckBox)row.FindControl("chkInnerLink");
                                Label    lblMenuLinkTextInner = (Label)row.FindControl("lblMenuLinkTextInner");
                                int      hdnEmpRightID        = int.Parse(((HiddenField)row.FindControl("hdnEmpRightID")).Value);
                                if (hdnEmpRightID > 0)
                                {
                                    chkInner.Checked = true;
                                }
                                else
                                {
                                    chkInner.Checked = false;
                                }
                            }
                        }
                        else
                        {
                            // rptInnerRights.DataSource = Nothing
                            // rptInnerRights.DataBind()
                            grdInnerRights.DataSource = null;
                            grdInnerRights.DataBind();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int userID = getCurrentUserID();

            if (!IsPostBack)
            {
                //int userID = getCurrentUserID();
                using (ERP_CMSEntities cntx = new ERP_CMSEntities())
                {
                    bool isAdmin = (bool)cntx.Users.Where(f => f.UserID == userID).Select(f => f.IsAdmin).FirstOrDefault();
                    if (!isAdmin)
                    {
                        var   havePageRights = cntx.sp_GetPageRightsByUserAndMenuLinkID(userID, Convert.ToInt32(PortalUtilities.MenuLinks.ManageUsers)).Where(f => f.UserRightID > 0).ToList();
                        IList listRights     = havePageRights.Select(f => f.Title).ToList();
                        if (havePageRights != null && havePageRights.Count > 0)
                        {
                            if (!listRights.Contains("List User"))
                            {
                                Response.Redirect("~/Admin/");
                            }
                            if (!listRights.Contains("Add User"))
                            {
                                pnlAdd.Visible = false;
                            }
                        }
                    }

                    try
                    {
                        var obj = (from d in cntx.Users
                                   orderby d.UserName
                                   select new { d.UserID, d.UserName, d.IsAdmin, d.IsActive }).ToList();
                        ddlUser.DataValueField = "UserID";
                        ddlUser.DataTextField  = "UserName";
                        ddlUser.DataSource     = obj;
                        ddlUser.DataBind();
                        ddlUser.Items.Insert(0, new ListItem("-- Select User --", ""));
                    }
                    catch (Exception ex)
                    {
                        lblStatus.Text = ex.Message;
                    }
                    GetUsers(cntx, 0);
                }
            }
        }
Example #4
0
        protected void grdAssignedRights_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
        {
            using (ERP_CMSEntities cntx = new ERP_CMSEntities())
            {
                int id        = int.Parse(grdAssignedRights.DataKeys[e.RowIndex].Value.ToString());
                int intUserID = int.Parse(ddlUser.SelectedValue);

                lblStatus.Text = string.Empty;
                lblMsg.Text    = string.Empty;

                try
                {
                    // Dim obj = New PortalModel.EmpLinks With {.EmpLinkID = id}
                    var obj           = cntx.UserLinks.Where(f => f.UserLinkID == id).ToList().FirstOrDefault();
                    int intMenuLinkID = (int)obj.MenuLinkID;


                    cntx.UserLinks.Attach(obj);
                    cntx.UserLinks.Remove(obj);


                    var objInner = cntx.sp_GetPageRightsByUserAndMenuLinkID(intUserID, intMenuLinkID).Where(f => f.UserRightID > 0).ToList();
                    foreach (var o in objInner)
                    {
                        var objEmpRights = cntx.UserRights.Where(f => f.PageRightID == o.PageRightID).ToList().FirstOrDefault();
                        {
                            cntx.UserRights.Attach(objEmpRights);
                            cntx.UserRights.Remove(objEmpRights);
                        }
                    }


                    cntx.SaveChanges();
                    GetRights(cntx);
                    lblStatus.ForeColor = System.Drawing.Color.DarkGreen;
                    lblStatus.Text      = "Right Deleted Successfully.";
                    lblMsg.Text         = "Right Deleted Successfully.";
                }
                catch (Exception ex)
                {
                    lblStatus.ForeColor = System.Drawing.Color.Red;
                    lblStatus.Text      = ex.Message;
                }
            }
        }
Example #5
0
        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;
                    }
                }
            }
        }