コード例 #1
0
        private void PrepareStudentCounselingRequestModel(AppointmentByStudentModel model)
        {
            // Add the corresponding counseler to the view model.
            var student   = Student;
            var @class    = _classRepository.GetById(student.ClassId);
            var counseler = CounselerRepository.GetById(@class.CounselerId);

            model.Counseler = Mapper.Map <CounselerModel>(counseler);
        }
コード例 #2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                // Check if the email exists in the students table.
                var student = StudentRepository.GetByEmail(model.Email);
                if (student != null)
                {
                    // Verify the hashed password in the database with the specified password.
                    if (Crypto.VerifyHashedPassword(student.Password, model.Password))
                    {
                        // Set an authentication cookie.
                        FormsAuthentication.SetAuthCookie(student.Email, true);

                        if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
                        {
                            // Redirect to the returl url in the query string, if specified.
                            return(Redirect(returnUrl));
                        }
                        return(RedirectToAction("Dashboard", "Students"));
                    }
                }

                // The email address is not from a student,
                // check if a counseler with the email address exists.
                var counseler = CounselerRepository.GetByEmail(model.Email);
                if (counseler != null)
                {
                    // Verify the hashed password in the database with the specified password.
                    if (Crypto.VerifyHashedPassword(counseler.Password, model.Password))
                    {
                        // Set an authentication cookie.
                        FormsAuthentication.SetAuthCookie(counseler.Email, true);

                        if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
                        {
                            // Redirect to the returl url in the query string, if specified.
                            return(Redirect(returnUrl));
                        }
                        return(RedirectToAction("Dashboard", "Counseler"));
                    }
                }

                // Email adress is not a student nor a counseler.
                ModelState.AddModelError("", "Je gebruikersnaam of wachtwoord klopt niet.");
            }

            return(View(model));
        }
コード例 #3
0
        public ActionResult AppointmentByStudent(AppointmentByStudentModel model)
        {
            // A student wishes to make an appointment with their counseler.
            if (ModelState.IsValid)
            {
                // Get the logged in student and counseler of the class the student is in.
                var student   = Student;
                var @class    = _classRepository.GetById(student.ClassId);
                var counseler = CounselerRepository.GetById(@class.CounselerId);

                if (counseler != null && student != null)
                {
                    // Create the appointment for the student and couseler.
                    var appointment = new Appointment
                    {
                        CounselerId = counseler.Id,
                        StudentId   = student.Id,
                        DateTime    = model.DateTime,
                        Location    = model.Location
                    };

                    int id = _appointmentRepository.Add(appointment);

                    // Send the appointment request mail.
                    var mail = new AppointmentMail
                    {
                        Counseler     = counseler,
                        Student       = student,
                        DateTime      = appointment.DateTime,
                        Location      = appointment.Location,
                        AcceptUrl     = FullUrl("AppointmentResponse", new { id }),
                        FromCounseler = false
                    };

                    _mailHelper.SendAppointmentMail(mail);

                    return(RedirectToAction("Details", "Appointment", new { id }));
                }
            }

            PrepareStudentCounselingRequestModel(model);
            return(View(model));
        }
コード例 #4
0
 private void PrepareClassModel(ClassModel model)
 {
     model.CounselerList = SelectList(CounselerRepository.GetAll(),
                                      c => c.Id,
                                      c => c.GetFullName());
 }