public void Email(Guid id)
        {
            GMailer.GmailUsername = "******";
            GMailer.GmailPassword = "******";

            GMailer mailer = new GMailer();

            mailer.ToEmail = db.Person.OfType <Employee>().Include(e => e.HomeAddress).Where(e => e.ID == id).FirstOrDefault().HomeAddress.Email;
            mailer.Subject = "Your Pay Stub";
            mailer.Body    = "";
            mailer.IsHtml  = true;
            mailer.Send();

            RedirectToAction("EmployeeIndex");
        }
Ejemplo n.º 2
0
        // Binds the Edit views values to controller
        public ActionResult Edit([Bind(Include = "ID,EmployeeID,Timestamp,Activity")] Attendance attendance)
        {
            if (ModelState.IsValid)
            {
                db.Entry(attendance).State = EntityState.Modified;                                                                                                       // Sets the state of the entry as Modified
                var oldTime   = db.Entry(attendance).GetDatabaseValues().GetValue <DateTime>("Timestamp").ToString();                                                    // gets the old timestamp
                var oldStatus = db.Entry(attendance).GetDatabaseValues().GetValue <Status>("Activity").ToString();                                                       // gets the old activity
                var newTime   = db.Entry(attendance).CurrentValues["Timestamp"];                                                                                         // gets the new timestamp
                GMailer.GmailUsername = "******";                                                                                                        // gmail sender credentials
                GMailer.GmailPassword = "******";                                                                                                                 // gmail sender credentials

                GMailer mailer = new GMailer();                                                                                                                          // instance of customer mailer class
                mailer.ToEmail = db.Person.OfType <Employee>().Include(e => e.HomeAddress).Where(e => e.ID == attendance.EmployeeID).FirstOrDefault().HomeAddress.Email; // gets the email of employee associated with attendance record
                mailer.Subject = "MVC Health App: Your hours have been changed";                                                                                         // subject of email
                mailer.Body    = $"<h3>Your shift has been changed from:</h3><p>{oldTime} <b>{oldStatus}</b></p>" +
                                 $"<h3>to</h3><p>{db.Entry(attendance).CurrentValues["Timestamp"]} <b>{db.Entry(attendance).CurrentValues["Activity"]}</b></p>";         // email contents
                mailer.IsHtml = true;
                db.SaveChanges();                                                                                                                                        // saves the modified attendance
                mailer.Send();                                                                                                                                           // send email to employee of modified attendance
                return(RedirectToAction("Index"));                                                                                                                       // redirect to Index view of Attendance
            }
            ViewBag.EmployeeID = new SelectList(db.Employee, "ID", "EmployeeID", attendance.EmployeeID);                                                                 // populates dropdown list with EmployeeI
            return(View(attendance));                                                                                                                                    // render Edit view with selected Attendance attributes
        }