示例#1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Page.Validate();
        if (Page.IsValid)
        {
            try
            {
                if (!string.IsNullOrEmpty(txtpwd.Text) && txtpwd.Text.Length < 6)
                {
                    string script = "alertify.alert('" + ltrSixChars.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                    return;
                }

                var checkedroles = (from ListItem item in Chkboxroles.Items where item.Selected select item.Text).ToList();
                if (!checkedroles.Any())
                {
                    string script = "alertify.alert('" + ltrSelectRole.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                    MaintainScrollPositionOnPostBack = false;
                    return;
                }
                if (Session[enumSessions.UserIdToUpdate.ToString()] == null)
                {
                    txtuname.Enabled = true;
                    if (!string.IsNullOrEmpty(txtpwd.Text.ToString().Trim()) && !string.IsNullOrEmpty(Txtuemail.Text.ToString().Trim()) && !string.IsNullOrEmpty(txtuname.Text.ToString().Trim()) && !string.IsNullOrEmpty(txtAnswer.Text.ToString().Trim()))
                    {
                        string username = txtuname.Text.ToString().Trim();
                        string password = txtpwd.Text.ToString().Trim();
                        string Emailid  = Txtuemail.Text.ToString().Trim();
                        string question = ddlSecurityQuestion.SelectedValue;
                        string answer   = txtAnswer.Text.ToString().Trim();
                        MembershipCreateStatus res;
                        MembershipUser         usr = Membership.CreateUser(username, password, Emailid, question, answer, ChkBoxIsapproved.Checked, out res);
                        if (usr == null)
                        {
                            string script = "alertify.alert('" + res.ToString() + "');";
                            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                            return;
                        }
                        else
                        {
                            Session[enumSessions.UserIdToUpdate.ToString()] = new Guid(usr.ProviderUserKey.ToString());
                            string script = "alertify.alert('User " + txtuname.Text + " created successfully.');";
                            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                            MaintainScrollPositionOnPostBack = false;
                        }
                    }
                }

                //updating user
                else
                {
                    if (!string.IsNullOrEmpty(Txtuemail.Text.ToString().Trim()) && !string.IsNullOrEmpty(txtuname.Text.ToString().Trim()))
                    {
                        txtuname.Enabled = false;
                        string         username = txtuname.Text.ToString().Trim();
                        string         password = txtpwd.Text.ToString().Trim();
                        string         Emailid  = Txtuemail.Text.ToString().Trim();
                        string         question = ddlSecurityQuestion.SelectedValue;
                        string         answer   = txtAnswer.Text.ToString().Trim();
                        MembershipUser user;
                        user = Membership.GetUser(new Guid(Session[enumSessions.UserIdToUpdate.ToString()].ToString()));
                        db   = new LinqToSqlDataContext();
                        var usrDtls = db.USP_GetUserDetailsByUserId(Session[enumSessions.UserIdToUpdate.ToString()].ToString()).FirstOrDefault();
                        //  string cur_pwd = user.GetPassword(usrDtls.PasswordAnswer);
                        //  user.ChangePasswordQuestionAndAnswer(cur_pwd, question, answer);//unable to retriee the password as password is hashed.

                        if (ChkBoxIsBlocked.Checked == false)
                        {
                            user.UnlockUser();
                        }
                        if (!string.IsNullOrEmpty(txtpwd.Text.ToString()))
                        {
                            user.ChangePassword(Membership.Provider.ResetPassword(username, usrDtls.PasswordAnswer), txtpwd.Text.ToString().Trim());//changed by Priya.
                        }

                        user.Email = Emailid.Trim();

                        Boolean approved = true;
                        if (ChkBoxIsapproved.Checked)
                        {
                            approved = true;
                        }
                        else
                        {
                            approved = false;
                        }

                        user.IsApproved = approved;
                        Membership.UpdateUser(user);

                        //deleting old existing roles of this user
                        string[] Rls = { "ARC_Manager", "ARC_Admin" };

                        foreach (string Urole in Rls)
                        {
                            if (Roles.IsUserInRole(txtuname.Text.ToString(), Urole))
                            {
                                Roles.RemoveUserFromRole(txtuname.Text.ToString(), Urole);
                            }
                        }

                        string script = "alertify.alert('User " + txtuname.Text + " updated successfully.');";
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                        MaintainScrollPositionOnPostBack = false;
                    }
                }

                //inserting checked roles
                for (int i = 0; i <= Chkboxroles.Items.Count - 1; i++)
                {
                    if (Chkboxroles.Items[i].Selected == true)
                    {
                        Roles.AddUserToRole(txtuname.Text.ToString(), Chkboxroles.Items[i].Text.ToString());
                    }
                }


                LoadData();
                MaintainScrollPositionOnPostBack = false;

                Audit audit = new Audit();
                audit.UserName  = Session[enumSessions.User_Name.ToString()].ToString();
                audit.ChangeID  = Convert.ToInt32(enumAudit.Update_User_Info);
                audit.CreatedOn = DateTime.Now;
                audit.IPAddress = Request.UserHostAddress;
                db.Audits.InsertOnSubmit(audit);
                db.SubmitChanges();
            }
            catch (Exception objException)
            {
                if (objException.Message.Trim() == "The E-mail supplied is invalid.")
                {
                    string script = "alertify.alert('" + ltrEmailExists.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                }
                db = new CSLOrderingARCBAL.LinqToSqlDataContext();
                db.USP_SaveErrorDetails(Request.Url.ToString(), "btnSave_Click", Convert.ToString(objException.Message), Convert.ToString(objException.InnerException), Convert.ToString(objException.StackTrace), "", HttpContext.Current.Request.UserHostAddress, false, Convert.ToString(HttpContext.Current.Session[enumSessions.User_Id.ToString()]));
            }
        }
        else
        {
            string script = "alertify.alert('" + ltrFill.Text + "');";
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
            MaintainScrollPositionOnPostBack = false;
        }
    }
示例#2
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Page.Validate();
        if (Page.IsValid)
        {
            try
            {
                //creating user

                if (ddlARC.SelectedValue == "-1")
                {
                    string script = "alertify.alert('" + ltrSelectARC.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                    MaintainScrollPositionOnPostBack = false;
                    return;
                }
                var checkedroles = (from ListItem item in Chkboxroles.Items where item.Selected select item.Value).ToList();
                if (!checkedroles.Any())
                {
                    string script = "alertify.alert('" + ltrSelectRole.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                    MaintainScrollPositionOnPostBack = false;
                    return;
                }
                string username = "";
                if (Session[enumSessions.UserIdToUpdate.ToString()] == null)
                {
                    txtuname.Enabled = true;
                    if (!string.IsNullOrEmpty(txtpwd.Text.ToString().Trim()) && !string.IsNullOrEmpty(Txtuemail.Text.ToString().Trim()) && !string.IsNullOrEmpty(txtuname.Text.ToString().Trim()))
                    {
                        username = txtuname.Text.ToString().Trim();
                        string password = txtpwd.Text.ToString().Trim();
                        string Emailid  = Txtuemail.Text.ToString().Trim();
                        string question = ddlSecurityQuestion.SelectedValue;
                        string answer   = txtAnswer.Text.ToString().Trim();
                        MembershipCreateStatus res;
                        MembershipUser         usr = Membership.CreateUser(username, password, Emailid, question, answer, ChkBoxIsapproved.Checked, out res);
                        if (usr == null)
                        {
                            string script = "alertify.alert('" + res.ToString() + "');";
                            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                            return;
                        }
                        else
                        {
                            Session[enumSessions.UserIdToUpdate.ToString()] = new Guid(usr.ProviderUserKey.ToString());
                            string script = "alertify.alert('User " + txtuname.Text + " created successfully.');";
                            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                            MaintainScrollPositionOnPostBack = false;
                        }
                    }
                }
                //updating user
                else
                {
                    if (!string.IsNullOrEmpty(Txtuemail.Text.ToString().Trim()) && !string.IsNullOrEmpty(txtuname.Text.ToString().Trim()))
                    {
                        txtuname.Enabled = false;
                        username         = txtuname.Text.ToString().Trim();
                        string         password = txtpwd.Text.ToString().Trim();
                        string         Emailid  = Txtuemail.Text.ToString().Trim();
                        string         question = ddlSecurityQuestion.SelectedValue;
                        string         answer   = txtAnswer.Text.ToString().Trim();
                        MembershipUser user;
                        user = Membership.GetUser(new Guid(Session[enumSessions.UserIdToUpdate.ToString()].ToString()));
                        db   = new LinqToSqlDataContext();
                        if (ChkBoxIsBlocked.Checked == false)
                        {
                            user.UnlockUser();
                        }
                        var usrDtls = db.USP_GetUserDetailsByUserId(Session[enumSessions.UserIdToUpdate.ToString()].ToString()).FirstOrDefault();
                        // string cur_pwd = user.GetPassword(usrDtls.PasswordAnswer);
                        // user.ChangePasswordQuestionAndAnswer(cur_pwd, question, answer);
                        if (!string.IsNullOrEmpty(txtpwd.Text.ToString()))
                        {
                            user.ChangePassword(Membership.Provider.ResetPassword(username, usrDtls.PasswordAnswer), txtpwd.Text);
                            // user.ChangePassword(cur_pwd, txtpwd.Text.ToString().Trim());
                        }

                        user.Email = Emailid.Trim();

                        Boolean approved = true;
                        if (ChkBoxIsapproved.Checked)
                        {
                            approved = true;
                        }
                        else
                        {
                            approved = false;
                        }


                        user.IsApproved = approved;
                        Membership.UpdateUser(user);

                        //deleting old existing roles of this user
                        string[] adminroles = (from a in db.ApplicationSettings
                                               where a.KeyName == enumApplicationSetting.WebsiteAdminRoles.ToString()
                                               select a.KeyValue).SingleOrDefault().Split(',');
                        var Rls = Roles.GetAllRoles().Except(adminroles).ToList();

                        foreach (string Urole in Rls)
                        {
                            if (Roles.IsUserInRole(txtuname.Text.ToString(), Urole))
                            {
                                Roles.RemoveUserFromRole(txtuname.Text.ToString(), Urole);
                            }
                        }

                        //deleting old existing arcs of this user

                        db = new LinqToSqlDataContext();
                        var delarc = db.ARC_User_Maps.Where(item => item.UserId == new Guid(Session[enumSessions.UserIdToUpdate.ToString()].ToString()));
                        db.ARC_User_Maps.DeleteAllOnSubmit(delarc);
                        db.SubmitChanges();

                        string script = "alertify.alert('User " + txtuname.Text + " updated successfully.');";
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                        MaintainScrollPositionOnPostBack = false;
                    }
                }

                string roleslist = string.Empty;
                //inserting checked roles
                for (int i = 0; i <= Chkboxroles.Items.Count - 1; i++)
                {
                    if (Chkboxroles.Items[i].Selected == true)
                    {
                        Roles.AddUserToRole(txtuname.Text.ToString(), Chkboxroles.Items[i].Value.ToString());
                        roleslist += Chkboxroles.Items[i].Value.ToString() + ",";
                    }
                }


                //inserting checked arcs of this user

                ARC_User_Map acm;
                if (ddlARC.SelectedValue != "-1" && ddlARC.SelectedValue != null)
                {
                    db         = new LinqToSqlDataContext();
                    acm        = new ARC_User_Map();
                    acm.UserId = new Guid(Session[enumSessions.UserIdToUpdate.ToString()].ToString());
                    acm.ARCId  = Convert.ToInt32(ddlARC.SelectedValue);
                    db.ARC_User_Maps.InsertOnSubmit(acm);
                    db.SubmitChanges();
                    int orderId = (from o in db.Orders
                                   where o.UserId == acm.UserId && o.ARCId != acm.ARCId && o.OrderStatusId == 1
                                   select o.OrderId).SingleOrDefault();
                    if (orderId > 0)
                    {
                        db.USP_DeleteOrderwithDetails(orderId);
                    }
                }


                pnluserdetails.Visible = false;
                pnluserlist.Visible    = true;

                Audit audit = new Audit();
                audit.UserName  = Session[enumSessions.User_Name.ToString()].ToString();
                audit.ChangeID  = Convert.ToInt32(enumAudit.Manage_User);
                audit.CreatedOn = DateTime.Now;
                audit.Notes     = "UserName: "******", Email: " + Txtuemail.Text + ", ARC: " + ddlARC.SelectedItem + ", IsApproved: " + ChkBoxIsapproved.Checked +
                                  ", IsBlocked:" + ChkBoxIsBlocked.Checked + ", Roles:" + roleslist;

                if (Request.ServerVariables["LOGON_USER"] != null)
                {
                    audit.WindowsUser = Request.ServerVariables["LOGON_USER"];
                }
                audit.IPAddress = Request.UserHostAddress;
                db.Audits.InsertOnSubmit(audit);
                db.SubmitChanges();

                LoadData();
                MaintainScrollPositionOnPostBack = false;
            }


            catch (Exception objException)
            {
                if (objException.Message.Trim() == "The E-mail supplied is invalid.")
                {
                    string script = "alertify.alert('" + ltrEmailExists.Text + "');";
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
                }
                db = new CSLOrderingARCBAL.LinqToSqlDataContext();
                db.USP_SaveErrorDetails(Request.Url.ToString(), "btnSave_Click", Convert.ToString(objException.Message), Convert.ToString(objException.InnerException), Convert.ToString(objException.StackTrace), "", HttpContext.Current.Request.UserHostAddress, false, Convert.ToString(HttpContext.Current.Session[enumSessions.User_Id.ToString()]));
            }
        }
        else
        {
            string script = "alertify.alert('" + ltrFill.Text + "');";
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", script, true);
            MaintainScrollPositionOnPostBack = false;
        }
    }
示例#3
0
    protected void LinkButtonupdate_click(object sender, System.EventArgs e)
    {
        try
        {
            btnSave.Visible       = true;
            divcreateuser.Visible = true;
            LinkButton  lbctg = sender as LinkButton;
            GridViewRow gvr   = (GridViewRow)lbctg.NamingContainer;
            Label       lbl1  = gvr.Cells[5].FindControl("UserKey") as Label;
            Session[enumSessions.UserIdToUpdate.ToString()] = lbl1.Text;
            db = new LinqToSqlDataContext();
            var usrDtls = db.USP_GetUserDetailsByUserId(lbl1.Text).FirstOrDefault();
            if (usrDtls.IsLockedOut)
            {
                ChkBoxIsBlocked.Enabled = true;
            }

            //new code for isapproved and locked out by sonam

            if (usrDtls.IsApproved == true)
            {
                ChkBoxIsapproved.Checked = true;
            }
            if (usrDtls.IsLockedOut == true)
            {
                ChkBoxIsBlocked.Checked = true;
            }
            txtuname.Text    = usrDtls.UserName;
            txtuname.Enabled = false;
            txtpwd.Text      = usrDtls.Password;
            ddlSecurityQuestion.SelectedValue = usrDtls.PasswordQuestion;
            txtAnswer.Text = usrDtls.PasswordAnswer;
            Txtuemail.Text = usrDtls.Email;

            foreach (ListItem itemchk in Chkboxroles.Items)
            {
                itemchk.Selected = false;
            }

            //bind user roles to checkboxroles
            string[] Rls = { "ARC_Admin", "ARC_Manager" };

            foreach (string Urole in Rls)
            {
                if (Roles.IsUserInRole(txtuname.Text.ToString(), Urole))
                {
                    foreach (ListItem itemchk in Chkboxroles.Items)
                    {
                        if (itemchk.Text == Urole)
                        {
                            itemchk.Selected = true;
                        }
                    }
                }
            }


            //binding user  to radioarc
        }
        catch (Exception objException)
        {
            db = new CSLOrderingARCBAL.LinqToSqlDataContext();
            db.USP_SaveErrorDetails(Request.Url.ToString(), "LinkButtonupdate_click", Convert.ToString(objException.Message), Convert.ToString(objException.InnerException), Convert.ToString(objException.StackTrace), "", HttpContext.Current.Request.UserHostAddress, false, Convert.ToString(HttpContext.Current.Session[enumSessions.User_Id.ToString()]));
        }
    }
示例#4
0
    protected void LinkButtonupdate_click(object sender, System.EventArgs e)
    {
        try
        {
            pnluserdetails.Visible   = true;
            pnluserlist.Visible      = false;
            litAction.Text           = "You choose to <b>EDIT USER</b>";
            ChkBoxIsapproved.Checked = false;
            LinkButton lbuser = sender as LinkButton;
            if (lbuser != null)
            {
                GridViewRow gvr  = (GridViewRow)lbuser.NamingContainer;
                Label       lbl1 = gvr.FindControl("UserKey") as Label;
                Session[enumSessions.UserIdToUpdate.ToString()] = lbl1.Text;
            }
            else
            {
                //Reset
                if (Session[enumSessions.UserIdToUpdate.ToString()] != null)
                {
                }
                else
                {
                    //Do a cancel as no value in session
                    btnCancel_Click(sender, e);
                }
            }

            db = new LinqToSqlDataContext();
            var usrDtls = db.USP_GetUserDetailsByUserId(Session[enumSessions.UserIdToUpdate.ToString()].ToString()).FirstOrDefault();
            if (usrDtls.IsLockedOut)
            {
                ChkBoxIsBlocked.Enabled = true;
            }
            //new code for isapproved and locked out by sonam
            if (usrDtls.IsApproved == true)
            {
                ChkBoxIsapproved.Checked = true;
            }
            if (usrDtls.IsLockedOut == true)
            {
                ChkBoxIsBlocked.Checked = true;
            }
            txtuname.Text    = usrDtls.UserName;
            txtuname.Enabled = false;
            txtpwd.Text      = usrDtls.Password;
            ddlSecurityQuestion.SelectedValue = usrDtls.PasswordQuestion;
            txtAnswer.Text = usrDtls.PasswordAnswer;
            Txtuemail.Text = usrDtls.Email;

            foreach (ListItem itemchk in Chkboxroles.Items)
            {
                itemchk.Selected = false;
            }

            //bind user roles to checkboxroles
            string[] adminroles = (from a in db.ApplicationSettings
                                   where a.KeyName == enumApplicationSetting.WebsiteAdminRoles.ToString()
                                   select a.KeyValue).SingleOrDefault().Split(',');
            var Rls = Roles.GetAllRoles().Except(adminroles).ToList();

            foreach (string Urole in Rls)
            {
                if (Roles.IsUserInRole(txtuname.Text.ToString(), Urole))
                {
                    foreach (ListItem itemchk in Chkboxroles.Items)
                    {
                        if (itemchk.Value == Urole)
                        {
                            itemchk.Selected = true;
                        }
                    }
                }
            }


            //binding user  to radioarc
            CheckArc();
        }
        catch (Exception objException)
        {
            db = new CSLOrderingARCBAL.LinqToSqlDataContext();
            db.USP_SaveErrorDetails(Request.Url.ToString(), "LinkButtonupdate_click", Convert.ToString(objException.Message), Convert.ToString(objException.InnerException), Convert.ToString(objException.StackTrace), "", HttpContext.Current.Request.UserHostAddress, false, Convert.ToString(HttpContext.Current.Session[enumSessions.User_Id.ToString()]));
        }
    }