protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                List <Employee_t> emp = Session["Employee"] as List <Employee_t>;
                using (PerformanceAppEntities db = new PerformanceAppEntities())
                {
                    string Username = emp[0].Username;
                    var    query    = db.Employee_t.Where(m => m.Password == OldTextBox.Text.Trim() && m.Username == Username);
                    if (query.Count() != 0)
                    {
                        Employee_t employee = query.Single();
                        employee.Password = NewTextBox.Text;
                        employee.PwdReset = 0;
                        db.SaveChanges();
                        lblError.Text   = "";
                        emp[0].Password = NewTextBox.Text;
                        emp[0].PwdReset = 0;
                        Response.Redirect("~/Dashboard.aspx", false);
                    }
                    else
                    {
                        lblError.Text = "Please enter correct old password";
                    }
                }
            }
            catch (Exception ex)
            {
                using (PerformanceAppEntities db = new PerformanceAppEntities())
                {
                    Log_t log = new Log_t();
                    log.Error_Message = ex.Message;

                    log.Page     = "ResetPassword";
                    log.Method   = "btnSubmit_Click";
                    log.Datetime = DateTime.Now;
                    db.Log_t.Add(log);
                    db.SaveChanges();
                    Response.Redirect("~/Login.aspx", false);
                }
            }
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                emp = Session["Employee"] as List <Employee_t>;
                Role_t role = new Role_t();
                if (emp != null)
                {
                    if (Session["Type"] != null)
                    {
                        type = Convert.ToInt32(Session["Type"].ToString());
                    }

                    if (emp[0].PwdReset == 1)
                    {
                        Response.Redirect("~/ResetPassword.aspx", false);
                    }



                    if (!Page.IsPostBack)
                    {
                        if (type == 1 || type == 2)
                        {
                            int empId = Convert.ToInt32(Request.QueryString["EmpId"].ToString());
                            using (PerformanceAppEntities db = new PerformanceAppEntities())
                            {
                                Session["Firstname"] = emp[0].Firstname;
                                Session["Lastname"]  = emp[0].Lastname;
                                //Getting the Reviewer or the appraiser object backup..
                                Session["Employee_Bckup"] = Session["Employee"];
                                emp = db.Employee_t.Where(m => m.Emp_Id == empId).ToList();
                                Session["Employee"] = emp;
                            }
                        }
                        using (PerformanceAppEntities db = new PerformanceAppEntities())
                        {
                            if (Session["Type"] != null)
                            {
                                if (type == 1)
                                {
                                    FromTextBox.Enabled    = false;
                                    ToTextBox.Enabled      = false;
                                    Responsibility.Enabled = false;
                                    Understanding.Enabled  = false;
                                }
                                else if (type == 2)
                                {
                                    FromTextBox.Enabled    = false;
                                    ToTextBox.Enabled      = false;
                                    Responsibility.Enabled = false;
                                    Understanding.Enabled  = false;
                                }
                                else if (type == 0)
                                {
                                }
                            }
                            empId = emp[0].Emp_Id;
                            var query = db.Appraisal_t.Where(m => m.EmpId == empId).ToList();
                            if (query.Count() != 0)
                            {
                                appraisal = query.Single();
                            }
                            Guid roleId = emp[0].RoleId ?? Guid.Empty;
                            role            = db.Role_t.Where(m => m.RoleId == roleId).Single();
                            Session["Role"] = role;
                            Role.Text       = role.Name;
                            if (appraisal != null)
                            {
                                Session["appraisal"] = appraisal;
                            }
                        }

                        if (appraisal != null)
                        {
                            FromTextBox.Text    = appraisal.From.Value.ToString("dd-MM-yyyy");
                            ToTextBox.Text      = appraisal.To.Value.ToString("dd-MM-yyyy");
                            Responsibility.Text = appraisal.Responsibility;
                            Understanding.Text  = appraisal.Understanding;
                        }

                        NameTextBox.Text = emp[0].Firstname + "" + emp[0].Lastname;
                        if (type == 0)
                        {
                            name.Text = emp[0].Firstname + "&nbsp;" + emp[0].Lastname;
                        }
                        else
                        {
                            name.Text = Session["Firstname"].ToString() + "&nbsp;" + Session["Lastname"].ToString();
                        }
                        DateofJoiningTextBox.Text = emp[0].Dateofjoining.Value.ToString("dd-MM-yyyy");
                        using (PerformanceAppEntities db1 = new PerformanceAppEntities())
                        {
                            if (emp[0].Appraiser != null)
                            {
                                int        appr = emp[0].Appraiser ?? 0;
                                Employee_t app  = db1.Employee_t.Where(m => m.Emp_Id == appr).Single();
                                AppraiserTextBox.Text = app.Firstname + "" + app.Lastname;
                            }
                            else
                            {
                                AppraiserTextBox.Text = "";
                            }
                            if (emp[0].Reviewer != null)
                            {
                                int        revr = emp[0].Reviewer ?? 0;
                                Employee_t rev  = db1.Employee_t.Where(m => m.Emp_Id == revr).Single();
                                ReviewerTextBox.Text = rev.Firstname + "" + rev.Lastname;
                            }
                            else
                            {
                                ReviewerTextBox.Text = "";
                            }
                        }

                        if (appraisal == null)
                        {
                            FromTextBox.Text = DateTime.Now.ToString("dd-MM-yyyy");
                            ToTextBox.Text   = DateTime.Now.AddDays(30).ToString("dd-MM-yyyy");
                        }
                    }
                }
                else
                {
                    Response.Redirect("~/Login.aspx", false);
                }
            }
            catch (Exception ex)
            {
                using (PerformanceAppEntities db = new PerformanceAppEntities())
                {
                    Log_t log = new Log_t();
                    log.Error_Message = ex.Message;

                    log.Page     = "PerformanceAppraisal";
                    log.Method   = "Page_Load";
                    log.Datetime = DateTime.Now;
                    db.Log_t.Add(log);
                    db.SaveChanges();
                    Response.Redirect("~/Login.aspx", false);
                }
            }
        }
Пример #3
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                using (PerformanceAppEntities db = new PerformanceAppEntities())
                {
                    var        query    = db.Employee_t.Where(m => m.Email == emailAddress.Text);
                    Employee_t employee = null;

                    if (query.Count() != 0)
                    {
                        employee          = query.Single();
                        employee.Password = RandomString(6);
                        employee.PwdReset = 1;
                        db.SaveChanges();
                        MailMessage mail        = new MailMessage();
                        var         fromAddress = "*****@*****.**"; // Gmail Address from where you send the mail
                        mail.To.Add(emailAddress.Text);
                        const string fromPassword = "******";        //Password of your gmail address
                        mail.Subject    = "Password Reset Request";
                        mail.IsBodyHtml = true;
                        mail.Body       = "<html><body><h1 align=\"left\"><img src=\"cid:image1\" /></h1><br/><h2 align=\"left\"><b>Password Reset</b></font></h2><br/>Dear " + employee.Firstname + ",<br/><br/>We received a request to reset the password associated with this e-mail address. If you made this request, then the new password is  " + employee.Password + ".<br/><br/> Click <a href=\"http://*****:*****@gmail.com");
                        AlternateView  av = AlternateView.CreateAlternateViewFromString(mail.Body, null, MediaTypeNames.Text.Html);
                        LinkedResource lr = new LinkedResource("E:\\trans.jpg", MediaTypeNames.Image.Jpeg);
                        lr.ContentId = "image1";
                        av.LinkedResources.Add(lr);
                        mail.AlternateViews.Add(av);
                        var smtp = new System.Net.Mail.SmtpClient();
                        {
                            smtp.Host           = "smtp.gmail.com";
                            smtp.Port           = 587;
                            smtp.EnableSsl      = true;
                            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                            smtp.Credentials    = new NetworkCredential(fromAddress, fromPassword);
                            smtp.Timeout        = 20000;
                        }
                        smtp.Send(mail);
                        lblError.Text = "Password is sent to your Email Address.";
                    }
                    else
                    {
                        lblError.Text = "Invalid Email Address";
                    }
                }
            }
            catch (Exception ex)
            {
                using (PerformanceAppEntities db = new PerformanceAppEntities())
                {
                    Log_t log = new Log_t();
                    log.Error_Message = ex.Message;

                    log.Page     = "ForgotPassword";
                    log.Method   = "btnSend_Click";
                    log.Datetime = DateTime.Now;
                    db.Log_t.Add(log);
                    db.SaveChanges();
                    Response.Redirect("~/Login.aspx", false);
                }
            }
        }