Example #1
0
        //Hashing End8 */

        protected void cmdRegister_Click(object sender, EventArgs e)
        {
            using (PTCLEntities db = new PTCLEntities())
            {
                tblPtclUser u = new tblPtclUser();
                u.FirstName    = txtFirstName.Text;
                u.LastName     = txtLastName.Text;
                u.EmailAddress = txtEmail.Text;
                u.Cnic         = txtCnic.Text;
                u.Phone        = txtPhone.Text;
                u.Status       = true;

                u.landline = txtLandLineNumber.Text;

                //Location Code
                u.LocationID = Convert.ToInt32(ddlLocationCode.SelectedValue);

                if (FileUpload.HasFile)
                {
                    FileUpload.SaveAs(Server.MapPath("UploadFiles/CustomerProfile/" + FileUpload.FileName));
                    u.CustomerDP = FileUpload.FileName;
                }
                else
                {
                    u.CustomerDP = "";
                }

                //u.Password = txtPassword.Text;

                //hashing password start
                var password = txtPassword.Text;
                var salt     = CreateSalt();
                var hash     = HashPassword(password, salt);
                //Response.Write(Convert.ToBase64String(hash));
                u.Password = (Convert.ToBase64String(hash));

                //hashing password end

                var check  = db.uniqueEmail(txtEmail.Text).ToList();
                var check1 = db.spUniqueLandline(txtLandLineNumber.Text).ToList();
                //Response.Write(check.Count);

                if (check.Count == 0)
                {
                    if (check1.Count == 0)
                    {
                        db.tblPtclUsers.Add(u);
                        db.SaveChanges();
                        lblMsg.Text = "Registration Completed Succcessfully";
                    }
                    else
                    {
                        lblMsg.Text = "LandLine Already Takken";
                    }
                }
                else
                {
                    lblMsg.Text = "Email Already Takken";
                }
            }
        }
        protected void cmdUpdate_Click(object sender, EventArgs e)
        {
            using (PTCLEntities db = new PTCLEntities())
            {
                if (Session["UserID"] != null)
                {
                    int         UserID = Convert.ToInt32(Session["UserID"]);
                    tblPtclUser u      = db.tblPtclUsers.FirstOrDefault(v => v.UserID == UserID);
                    u.FirstName    = txtMyName.Text;
                    u.LastName     = txtLastName.Text;
                    u.EmailAddress = txtEmail.Text;
                    u.Phone        = txtPhone.Text;
                    u.Cnic         = txtCnic.Text;
                    //u.Password = txtPassword.Text;
                    u.landline = txtLandLineNumber.Text;

                    var password = txtPassword.Text;
                    var salt     = CreateSalt();
                    var hash     = HashPassword(password, salt);

                    u.LocationID = Convert.ToInt32(ddlLocationCode.SelectedValue);
                    u.Password   = (Convert.ToBase64String(hash));

                    if (FileUpload.HasFile)
                    {
                        FileUpload.SaveAs(Server.MapPath("../../UploadFiles/CustomerProfile/" + FileUpload.FileName));
                        u.CustomerDP = FileUpload.FileName;
                    }
                    else
                    {
                        u.CustomerDP = "";
                    }

                    var check  = db.uniqueEmail(txtEmail.Text).ToList();
                    var check1 = db.spUniqueLandline(txtLandLineNumber.Text).ToList();
                    if (check.Count == 1)
                    {
                        if (check1.Count == 1)
                        {
                            db.tblPtclUsers.Add(u);
                            db.SaveChanges();
                            lblMsg.Text = "Registration Completed Succcessfully";
                        }
                        else
                        {
                            lblMsg.Text = "LandLine Already Takken";
                        }
                    }
                    else
                    {
                        lblMsg.Text = "Email Already Takken";
                    }
                }

                /*var check = db.uniqueEmail(txtEmail.Text).ToList();
                 * var check1 = db.spUniqueLandline(txtLandLineNumber.Text).ToList();
                 *
                 * if (u.landline == txtLandLineNumber.Text || u.EmailAddress == txtEmail.Text)
                 * {
                 *  db.SaveChanges();
                 *  lblMsg.Text = "Registration Completed Succcessfully";
                 * }
                 * else if (check.Count == 0)
                 * {
                 *  if (check1.Count == 0)
                 *  {
                 *      db.SaveChanges();
                 *      lblMsg.Text = "Registration Completed Succcessfully";
                 *  }
                 *  else
                 *  {
                 *      lblMsg.Text = "LandLine Already Takken";
                 *  }
                 * }
                 * else
                 *  lblMsg.Text = "Email Already Takken";
                 * }*/
            }
        }
        protected void cmdCreate_Click(object sender, EventArgs e)
        {
            using (PTCLEntities db = new PTCLEntities())
            {
                if (Request.QueryString["AdminID"] == null)
                {
                    tblAdmin s = new tblAdmin();
                    s.UserName = txtUserName.Text;
                    //s.Password = txtPassword.Text;
                    s.FullName     = txtFullName.Text;
                    s.EmailAddress = txtEmailAddress.Text;
                    s.Location     = txtLocation.Text;
                    s.AdminPhone   = txtPhone.Text;

                    if (FileUpload.HasFile)
                    {
                        FileUpload.SaveAs(Server.MapPath("../../UploadFiles/AdminProfile/" + FileUpload.FileName));
                        s.AdminDP = FileUpload.FileName;
                    }
                    else
                    {
                        s.AdminDP = "";
                    }

                    var password = txtPassword.Text;
                    var salt     = CreateSalt();
                    var hash     = HashPassword(password, salt);
                    s.Password = Convert.ToBase64String(hash);

                    //s.Status = txtStatus.Text;
                    s.Status = bool.Parse(ddlStatus.SelectedValue.ToString());
                    // s.Status = Boolean.TryParse(ddlStatus.SelectedValue.ToString);
                    var check  = db.uniqueEmail(txtEmailAddress.Text).ToList();
                    var check1 = db.uniqueUserName(txtUserName.Text).ToList();
                    if (check.Count == 0)
                    {
                        if (check1.Count == 0)
                        {
                            db.tblAdmins.Add(s);
                            db.SaveChanges();
                            lblMsg.Text = "Admin Inserted Successfully";
                        }
                        else
                        {
                            lblMsg.Text = "UserName Already Takken";
                        }
                    }
                    else
                    {
                        lblMsg.Text = "Email Already Takken";
                    }
                }
                else
                {
                    var      password = txtPassword.Text;
                    var      salt     = CreateSalt();
                    var      hash     = HashPassword(password, salt);
                    int      AdminID  = Convert.ToInt32(Request.QueryString["AdminID"]);
                    tblAdmin s        = db.tblAdmins.FirstOrDefault(v => v.AdminID == AdminID);
                    s.Password = Convert.ToBase64String(hash);
                    s.UserName = txtUserName.Text;
                    //s.Password = txtPassword.Text;
                    s.FullName     = txtFullName.Text;
                    s.EmailAddress = txtEmailAddress.Text;
                    s.Location     = txtLocation.Text;
                    s.AdminPhone   = txtPhone.Text;

                    if (FileUpload.HasFile)
                    {
                        FileUpload.SaveAs(Server.MapPath("../../UploadFiles/AdminProfile/" + FileUpload.FileName));
                        s.AdminDP = FileUpload.FileName;
                    }
                    else
                    {
                        s.AdminDP = "";
                    }

                    //s.Status = txtStatus.Text;
                    s.Status = bool.Parse(ddlStatus.SelectedValue);
                    //s.Status = bool.Parse(ddlStatus.SelectedValue.ToString());
                    //s.Status = Convert.ToBoolean(ddlStatus.SelectedValue);
                    var check  = db.uniqueEmail(txtEmailAddress.Text).ToList();
                    var check1 = db.uniqueUserName(txtUserName.Text).ToList();
                    if (check.Count == 1)
                    {
                        if (check1.Count == 1)
                        {
                            db.SaveChanges();
                            lblMsg.Text = "Admin Updated Successfully";
                        }
                        else
                        {
                            lblMsg.Text = "UserName Already Takken";
                        }
                    }
                    else
                    {
                        lblMsg.Text = "Email Already Takken";
                    }
                }
            }
        }