예제 #1
0
        public ActionResult PickAppointment(UserModel user)
        {
            TestDatabaseEntities context = new TestDatabaseEntities();

            if (user != null)
            {
                if (context.Appointments.Where(x => x.StudentUserID == user.UserID).FirstOrDefault() == null)
                {
                    var selection   = context.Availabilities.Where(x => x.AvailabilityID == user.SelectedAvailId).FirstOrDefault();
                    var instructor  = context.UserLogins.Where(x => x.UserID == selection.InstructorUserID).FirstOrDefault();
                    var confirmCode = Guid.NewGuid();
                    context.InsertAppointment(user.UserID, selection.InstructorUserID, selection.DateTime, confirmCode, selection.AvailabilityID);

                    SendConfirmAptEmail(instructor.Email, confirmCode.ToString(), user);
                    ViewBag.Message = "You have successfully asked for an meeting with " + instructor.Username.ToString() + ". We will notify you when they have confirmed the appointment.";
                    RedirectToAction("ProfilePage");
                }
                else
                {
                    ViewBag.Message = "You have already signed up for an appointment.";
                    RedirectToAction("ProfilePage");
                }
            }


            return(RedirectToAction("ProfilePage"));
        }