Example #1
0
        public ActionResult ConfirmApt(string confirmCode)
        {
            TestDatabaseEntities context = new TestDatabaseEntities();
            var v          = context.Appointments.Where(x => x.confirmCode == new Guid(confirmCode)).FirstOrDefault();
            var aptUser    = context.UserLogins.Where(x => x.UserID == v.StudentUserID).FirstOrDefault();
            var instructor = context.UserLogins.Where(x => x.UserID == v.InstructorUserID).FirstOrDefault();
            var availId    = v.OriginalAvailID;

            if (v != null)
            {
                context.ConfirmApt(v.AppointmentID, aptUser.UserID, instructor.UserID);


                var    fromEmail         = new MailAddress("*****@*****.**", "PrepIN Support");
                var    toEmail           = new MailAddress(aptUser.Email);
                var    fromEmailPassword = "******";
                string subject           = "Confirmation of Appointment";

                string body = "</br> </br> Your appointment with " + instructor.Username.ToString() + " for " + v.Time.ToLongDateString() + " at " + v.Time.ToShortTimeString() + " has been confirmed!";


                var smtp = new SmtpClient
                {
                    Host                  = "lv-shared04.cpanelplatform.com",
                    Port                  = 587,
                    EnableSsl             = true,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(fromEmail.Address, fromEmailPassword)
                };

                using (var message = new MailMessage(fromEmail, toEmail)
                {
                    Subject = subject,
                    Body = body,
                    IsBodyHtml = true
                })
                    smtp.Send(message);



                ViewBag.Message = "You have successfully confirmed your appointment with " + aptUser.Username + ".";
                context.DeleteAvail(availId);
                return(RedirectToAction("ProfilePage"));
            }
            else
            {
                ViewBag.Message = "An error has occured. Redirecting you to profile page or login page.";
                return(RedirectToAction("ProfilePage"));
            }
        }