private void GetData()
        {
            if (ViewState["ID"] != null)
            {
                string ID = ViewState["ID"].ToString();


                var QUERY = new VisitorsDataContext().UsersSearch(ID).ToList <UsersSearchResult>();

                foreach (var item in QUERY)
                {
                    txtUserName.Text = item.UserName;
                    string role = string.Empty;
                    if (item.UserRole.Equals("admin"))
                    {
                        rbManger.Checked = true;
                        rbEmp.Checked    = false;
                    }
                    else
                    {
                        rbManger.Checked = false;
                        rbEmp.Checked    = true;
                    }
                    if (!item.UserGender)
                    {
                        rbFemale.Checked = true;
                    }
                    ddlDepartments.SelectedValue = ActiveDirectoryManagment.GetDepartment(ID);
                    GetAllUsersByDepartment();
                    ddlUsers.SelectedValue = ID;
                }
                ddlDepartments.Enabled = false;
                ddlUsers.Enabled       = false;
            }
        }
Beispiel #2
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        try
        {
            string Msg        = string.Empty;
            string UserRoleId = string.Empty;
            string UserId     = txtUserName.Text;
            bool   isValid    = ActiveDirectoryManagment.ValidateUser(txtUserName.Text, txtPassword.Text);
            var    q          = new VisitorsDataContext().IsValidUser(txtUserName.Text).Single();

            if (q != null && isValid & (bool)!q.UserIsLocked)
            {
                HttpCookie UserWebsiteId = new HttpCookie("UserWebsiteId");
                UserWebsiteId.Value = UserId;
                Response.Cookies.Add(UserWebsiteId);

                HttpCookie UserGender = new HttpCookie("UserGender");
                UserGender.Value = q.UserGender.ToString();
                Response.Cookies.Add(UserGender);

                HttpCookie SecurityType = new HttpCookie("SecurityType");// if it is leader or Manager
                SecurityType.Value = q.UserRole;
                Response.Cookies.Add(SecurityType);

                if (chkRemberMe.Checked)
                {
                    UserWebsiteId.Expires = DateTime.Now.AddDays(30);
                    SecurityType.Expires  = DateTime.Now.AddDays(30);
                    UserGender.Expires    = DateTime.Now.AddDays(30);
                }
                else
                {
                    UserWebsiteId.Expires = DateTime.Now.AddDays(-1);
                    SecurityType.Expires  = DateTime.Now.AddDays(-1);
                    UserGender.Expires    = DateTime.Now.AddDays(-1);
                }


                if (Request.QueryString["page"] == null)
                {
                    Response.Redirect("Vistors/CheckIn.aspx");
                }
                else
                {
                    Response.Redirect(Request.QueryString["page"].ToString());
                }
            }
            else
            {
                DivMsg.Visible = true;
            }
        }
        catch (Exception ex)
        {
            DivMsg.Visible = true;
            Helper.LogError(ex);
        }
    }
    private void getData()
    {
        ManageGroups();
        if (ViewState["ID"] != null)
        {
            string ID    = ViewState["ID"].ToString();
            var    QUERY = new StatisticsReportForReferenceServicesDataContext().UsersSearch(ID).ToList <UsersSearchResult>();
            foreach (var item in QUERY)
            {
                txtUserName.Text = item.User_Name;

                ddlDepartments.SelectedValue = ActiveDirectoryManagment.GetDepartment(ID);
                GetAllUsersByDepartment();
                ddlUsers.SelectedValue   = ID;
                ddlRealDep.SelectedValue = item.DepartmentID.ToString();
            }
            BindGroups(ID);
            //   rblRole.Items.FindByValue(((int)Helper.GroupsEnum.Admin).ToString()).Selected = true;
            ddlDepartments.Enabled = false;
            ddlUsers.Enabled       = false;
        }
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        try
        {
            string     Msg           = string.Empty;
            string     UserRoleId    = string.Empty;
            string     UserId        = txtUserName.Text;
            string     qUserId       = null;
            string     qGroups       = null;
            int        count         = 0;
            bool       isValid       = ActiveDirectoryManagment.validateUser(txtUserName.Text, txtPassword.Text);
            HttpCookie userWebsiteId = new HttpCookie("UserWebsiteId");
            HttpCookie securityType  = new HttpCookie("SecurityType");
            var        q             = new StatisticsReportForReferenceServicesDataContext().IsValidUser(txtUserName.Text).ToList();
            if (q != null && isValid)
            {
                foreach (var item in q)
                {
                    if (!item.User_Is_Locked)
                    {
                        qUserId = item.User_ID.ToString();

                        // if it is leader or Manager
                        qGroups += item.GroupID.ToString() + "|";
                    }
                    else
                    {
                        DivMsg.Visible = true;
                        break;
                    }
                }
                if (chkRemberMe.Checked)
                {
                    userWebsiteId.Expires = DateTime.Now.AddDays(30);
                    securityType.Expires  = DateTime.Now.AddDays(30);
                }
                else
                {
                    userWebsiteId.Expires = DateTime.Now.AddDays(1);
                    securityType.Expires  = DateTime.Now.AddDays(1);
                }

                userWebsiteId.Value = new CookieSecurityProvider().Protect(qUserId);
                securityType.Value  = new CookieSecurityProvider().Protect(qGroups);
                //userWebsiteId.Secure = true;

                Response.Cookies.Add(userWebsiteId);
                Response.Cookies.Add(securityType);
                if (Request.QueryString["page"] == null)
                {
                    Response.Redirect("/admin/ItemsAdd.aspx");
                }
                else
                {
                    Response.Redirect(Request.QueryString["page"].ToString());
                }
            }

            else
            {
                DivMsg.Visible = true;
            }
        }
        catch (Exception ex)
        {
            DivMsg.Visible   = true;
            DivMsg.InnerHtml = ex.Message;
        }
    }