Esempio n. 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            this.ClearMessagePanel();

            if (IsValid())
            {
                using (MSIPortalContext ctx = new MSIPortalContext())
                {
                    try
                    {
                        // Setup User
                        tbl_User user = new tbl_User();
                        user.UserID    = Guid.NewGuid();
                        user.LoginName = txtEmail.Text.Trim();
                        user.FirstName = txtFirstName.Text.Trim();
                        user.LastName  = txtLastName.Text.Trim();
                        user.RoleID    = ddlUserType.SelectedValue;
                        user.CityID    = ddlCity.SelectedValue;
                        user.IsActive  = true;
                        user.EditUser  = ((tbl_User)Session["User"]).UserID;
                        user.EditDate  = DateTime.Now;

                        //Setup Password
                        tbl_UserPassword pass = new tbl_UserPassword();
                        pass.UserID   = user.UserID;
                        pass.Password = txtPassword.Text.Trim();
                        pass.EditUser = ((tbl_User)Session["User"]).UserID;
                        pass.EditDate = DateTime.Now;

                        ctx.tbl_User.Add(user);
                        ctx.tbl_UserPassword.Add(pass);
                        ctx.SaveChanges();
                        this.ClearForm();
                        lblSuccessMessage.Text = "User created successfully.";
                        lblErrorMessage.Text   = string.Empty;
                        MessagePanel.Visible   = true;
                        txtEmail.Focus();
                        this.BindGrid();
                    }
                    catch (DbEntityValidationException dbEx)
                    {
                        foreach (var validationErrors in dbEx.EntityValidationErrors)
                        {
                            foreach (var validationError in validationErrors.ValidationErrors)
                            {
                                Trace.Write("Property: {0} Error: {1}" + validationError.PropertyName, validationError.ErrorMessage);
                            }
                        }
                    }
                    catch (Exception Ex)
                    {
                    }// End of Catch
                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (txtEmail.Text.Trim() == string.Empty)
            {
                lblSuccessMessage.Text = "Email required";
                return;
            }

            string password = string.Empty;

            using (MSIPortalContext ctx = new MSIPortalContext())
            {
                var result = from p in ctx.tbl_UserPassword where p.tbl_User.LoginName == txtEmail.Text.Trim() select p;
                tbl_UserPassword tblPassword = result.FirstOrDefault <tbl_UserPassword>();
                if (tblPassword != null)
                {
                    password = tblPassword.Password;
                }
            }

            if (password != string.Empty)
            {
                try
                {
                    var client = new SmtpClient("smtp.gmail.com", 587)
                    {
                        Credentials = new NetworkCredential("*****@*****.**", "posting2014"),
                        EnableSsl   = true
                    };
                    client.Send("*****@*****.**", txtEmail.Text.Trim(), "Password Recovery", "Your Lost password: "******"Your password has been sent to your email.";
                    txtEmail.Text          = string.Empty;
                    txtEmail.Focus();
                    lblErrorMessage.Text = string.Empty;
                }
                catch (Exception ex)
                {
                    lblErrorMessage.Text   = "Error occured.";
                    lblSuccessMessage.Text = string.Empty;
                }
            }
            else
            {
                lblErrorMessage.Text   = "Email does not exist.";
                lblSuccessMessage.Text = string.Empty;
            }
        }
        private void FillAboutYouSecttion(tbl_User user)
        {
            tbl_UserPassword pass = FindPasswordByUserId(user.UserID).FirstOrDefault <tbl_UserPassword>();

            txtUserEmail.Text             = user.LoginName.Trim();
            txtPassword.Text              = pass.Password.Trim();
            txtConfirmPassword.Text       = pass.Password.Trim();
            txtUserFirstlName.Text        = user.FirstName.Trim();
            txtUserLastName.Text          = user.LastName.Trim();
            ddlUserLocation.SelectedValue = user.CityID.Trim();


            //Disable Controls
            txtUserEmail.Enabled        = false;
            txtPassword.Enabled         = false;
            txtConfirmPassword.Enabled  = false;
            txtUserFirstlName.Enabled   = false;
            txtUserLastName.Enabled     = false;
            ddlUserLocation.Enabled     = false;
            lblUserEmailValidation.Text = string.Empty;
        }
Esempio n. 4
0
        protected void btnUpdatePassword_Click(object sender, EventArgs e)
        {
            tbl_User user = (tbl_User)Session["User"];

            using (MSIPortalContext ctx = new MSIPortalContext())
            {
                var pass = from p in ctx.tbl_UserPassword
                           where p.Password == txtExistingPassword.Text.Trim() && p.tbl_User.LoginName == user.LoginName
                           select p;
                tbl_UserPassword password = pass.FirstOrDefault <tbl_UserPassword>();

                if (password != null)
                {
                    if (txtNewPassword.Text.Trim() == txtConfirmNewPassword.Text.Trim())
                    {
                        password.Password         = txtNewPassword.Text.Trim();
                        ctx.Entry(password).State = EntityState.Modified;
                        ctx.SaveChanges();
                        txtExistingPassword.Text   = string.Empty;
                        txtNewPassword.Text        = string.Empty;
                        txtConfirmNewPassword.Text = string.Empty;

                        cpSuccessMessage.Text = "Password changed successfully";
                        cpErrorMessage.Text   = string.Empty;
                        txtExistingPassword.Focus();
                    }
                    else
                    {
                        cpSuccessMessage.Text = string.Empty;
                        cpErrorMessage.Text   = "New password and confirm new password miss match.";
                    }
                }
                else
                {
                    cpSuccessMessage.Text = string.Empty;
                    cpErrorMessage.Text   = "Provided password does not exist.";
                }
            }
        }
        private void SavePost()
        {
            ClearMessagePanel();
            using (MSIPortalContext ctx = new MSIPortalContext())
            {
                try
                {
                    tbl_Post         post     = new tbl_Post();
                    tbl_User         user     = new tbl_User();
                    tbl_UserPassword password = new tbl_UserPassword();

                    //===========Initialize the User Table
                    if (Session["User"] != null)
                    {
                        user = (tbl_User)Session["User"];
                    }
                    else if (FindUserByEmailAndPassword().Count > 0)
                    {
                        user = FindUserByEmailAndPassword().FirstOrDefault <tbl_User>();
                    }
                    else if (FindUserByEmailAndPassword().Count == 0) // If Existing User but not Logged In  [Eaml&Password Count May be 0]
                    {
                        if (FindUserByEmailOnly().Count == 0)         // Insert only if this email is completely new [Email count may be greater than 0]
                        {
                            //Set User
                            user           = new tbl_User();
                            user.UserID    = Guid.NewGuid();
                            user.LoginName = this.txtUserEmail.Text.Trim();
                            user.FirstName = this.txtUserFirstlName.Text.Trim();
                            user.LastName  = this.txtUserLastName.Text.Trim();
                            user.RoleID    = "02"; // Ordinary User
                            user.CityID    = ddlUserLocation.SelectedValue;
                            user.IsActive  = true;
                            user.EditUser  = user.UserID;
                            user.EditDate  = DateTime.Now;

                            //Set Password
                            password.UserID   = user.UserID;
                            password.Password = txtPassword.Text.Trim();
                            password.EditUser = user.UserID;
                            password.EditDate = DateTime.Now;

                            //Add to Context
                            ctx.tbl_User.Add(user);
                            ctx.tbl_UserPassword.Add(password);
                        }
                        else
                        {
                            MessagePanel.Visible = true;
                            txtUserEmail.Focus();
                            lblUserEmailValidation.Text = "*";
                            lblErrorMessage.Text        = "Already registered email";
                            lblSuccessMessage.Visible   = false;
                            return; // Stop Inserting any Single Record
                        }
                    }

                    //============Initialize Post Table
                    post.PostID     = Guid.NewGuid();
                    post.CategoryID = ddlCategory.SelectedValue;
                    post.CityID     = ddlCommonCity.SelectedValue;


                    if (rdoCommonSales.Checked)
                    {
                        post.PSTID = "001";
                    }
                    else
                    {
                        post.PSTID = "002";
                    }

                    post.PostTitle       = this.txtCommonPostingTitle.Text.Trim();
                    post.PostDescription = this.txtCommonPostingDescription.Text.Trim();



                    if (commonImageUpload.PostedFile.FileName != string.Empty)
                    {
                        commonImageUpload.SaveAs(Server.MapPath("~/imageupload/" + post.PostID + ".jpg"));
                        post.ImageUrl = "/imageupload/" + post.PostID + ".jpg";
                    }
                    else
                    {
                        post.ImageUrl = "/Styles/images/" + "no_image.jpg";
                    }



                    post.PostingUserID     = user.UserID;
                    post.ProviderFirstName = txtCommonProviderFirstName.Text.Trim();
                    post.ProviderLastName  = txtCommonProviderLastName.Text.Trim();
                    post.ProviderAddress   = txtCommonProviderAddress.Text.Trim();
                    post.ProviderEmail     = txtCommonProviderEmil.Text.Trim();
                    post.ProviderPhoneNo   = txtCommonProviderPhone.Text.Trim();
                    post.Approved          = false;
                    post.Rank     = 999; // Default value to make sure out of rank
                    post.EditUser = user.UserID;
                    post.EditDate = DateTime.Now;

                    ctx.tbl_Post.Add(post);
                    ctx.SaveChanges();
                    //---------------After Successful Save Do the following operation
                    MessagePanel.Visible      = true;
                    lblSuccessMessage.Visible = true;
                    lblSuccessMessage.Text    = "Your posting is successful!";
                    //this.SendConfirmationEmail();
                    lblUserEmailValidation.Text = string.Empty;
                    this.ClearForm();
                    ddlCommonCountry.Focus();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.Write("Property: {0} Error: {1}" + validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (Exception Ex)
                {
                    Response.Write(Ex.ToString());
                } // End of Catch
            }     // End of Using
        }