<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Helpers;
using System.Web.Mvc;
using AutoMapper;
using Mandrill;
using StudentFollowingSystem.Data.Repositories;
using StudentFollowingSystem.Filters;
using StudentFollowingSystem.Models;
using StudentFollowingSystem.Services;
using StudentFollowingSystem.ViewModels;

namespace StudentFollowingSystem.Controllers
{
    public class StudentsController : ControllerBase
    {
        private readonly SubjectRepository _subjectRepository = new SubjectRepository();
        private readonly PresenceRepository _presenceRepository = new PresenceRepository();
        private readonly ClassRepository _classRepository = new ClassRepository();
        private readonly MandrillMailEngine _mailEngine = new MandrillMailEngine();

        [AuthorizeStudent]
        public ActionResult Dashboard()
        {
            var student = Student;

            var model = new StudentDashboardModel();
            var subjects = _subjectRepository.GetAll()
                                             .Where(s => s.StartDate.Date == DateTime.Now.Date)
                                             .ToList();
            model.Subjects = subjects;

            var presence = _presenceRepository.GetByStudent(student.Id);
            model.Presences = presence;
            return View(model);
        }

        [AuthorizeCounseler]
        public ActionResult List()
        {
            var students = Mapper.Map<List<StudentModel>>(StudentRepository.GetAll());
            return View(students);
        }

        [AuthorizeCounseler]
        public ActionResult Create()
        {
            var model = new StudentModel { EnrollDate = new DateTime(DateTime.Now.Year - 1, 9, 1) };
            PrepareStudentModel(model);
            return View(model);
        }

        [AuthorizeCounseler]
        [HttpPost]
        public ActionResult Create(StudentModel model)
        {
            if (ModelState.IsValid)
            {
                var duplicate = StudentRepository.GetByStudentNr(model.StudentNr.GetValueOrDefault());
                if (duplicate == null)
                {
                    // Map the  student view model to the domain model.
                    var student = Mapper.Map<Student>(model);
                    student.Active = true;

                    // Generate a password for the student and hash it.
                    string password = PasswordGenerator.CreateRandomPassword();
                    student.Password = Crypto.HashPassword(password);
                    StudentRepository.Add(student);

                    // Create a mail message with the password and mail it to the student.
                    var msg = new EmailMessage
                                  {
                                      text = string.Format("Beste {1},{0}{0}Inlognaam: {3} {0}Wachtwoord: {2}{0}{0}",
                                          Environment.NewLine,
                                          student.FirstName,
                                          password,
                                          student.Email),
                                      subject = "Studenten Volg Systeem wachtwoord",
                                      to = new List<EmailAddress>
                                               {
                                                   new EmailAddress(student.Email, string.Format("{0} {1}", student.FirstName, student.LastName))
                                               },
                                  };
                    _mailEngine.Send(msg);

                    return RedirectToAction("List");
                }

                ModelState.AddModelError("", "Studentnummer komt al voor in de database.");
            }

            PrepareStudentModel(model);
            return View(model);
        }
<commit_msg>Change add student mail fixes #22<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Helpers;
using System.Web.Mvc;
using AutoMapper;
using Mandrill;
using StudentFollowingSystem.Data.Repositories;
using StudentFollowingSystem.Filters;
using StudentFollowingSystem.Models;
using StudentFollowingSystem.Services;
using StudentFollowingSystem.ViewModels;

namespace StudentFollowingSystem.Controllers
{
    public class StudentsController : ControllerBase
    {
        private readonly SubjectRepository _subjectRepository = new SubjectRepository();
        private readonly PresenceRepository _presenceRepository = new PresenceRepository();
        private readonly ClassRepository _classRepository = new ClassRepository();
        private readonly MandrillMailEngine _mailEngine = new MandrillMailEngine();

        [AuthorizeStudent]
        public ActionResult Dashboard()
        {
            var student = Student;

            var model = new StudentDashboardModel();
            var subjects = _subjectRepository.GetAll()
                                             .Where(s => s.StartDate.Date == DateTime.Now.Date)
                                             .ToList();
            model.Subjects = subjects;

            var presence = _presenceRepository.GetByStudent(student.Id);
            model.Presences = presence;
            return View(model);
        }

        [AuthorizeCounseler]
        public ActionResult List()
        {
            var students = Mapper.Map<List<StudentModel>>(StudentRepository.GetAll());
            return View(students);
        }

        [AuthorizeCounseler]
        public ActionResult Create()
        {
            var model = new StudentModel { EnrollDate = new DateTime(DateTime.Now.Year - 1, 9, 1) };
            PrepareStudentModel(model);
            return View(model);
        }

        [AuthorizeCounseler]
        [HttpPost]
        public ActionResult Create(StudentModel model)
        {
            if (ModelState.IsValid)
            {
                var duplicate = StudentRepository.GetByStudentNr(model.StudentNr.GetValueOrDefault());
                if (duplicate == null)
                {
                    // Map the  student view model to the domain model.
                    var student = Mapper.Map<Student>(model);
                    student.Active = true;

                    // Generate a password for the student and hash it.
                    string password = <PASSWORD>();
                    student.Password = <PASSWORD>(password);
                    StudentRepository.Add(student);

                    // Create a mail message with the password and mail it to the student.
                    var msg = new EmailMessage
                                  {
                                      text = string.Format("Beste {1},{0}{0}Hogeschool NHL maakt gebruikt van het Student volg systeem.{0}Hier kunnen studenten en SLB'ers de studie voortgang bekijken en bij houden. {0}De NHL heeft alvast een acount voor je aangenaakt, Dit zijn de gegevens: {0}{0}Inlognaam: {3} {0}Wachtwoord: {2}{0}{0}Met Vriendelijke groet,{0}{0} NHL Hogeschool",
                                          Environment.NewLine,
                                          student.FirstName,
                                          password,
                                          student.Email),
                                      subject = "Studenten Volg Systeem wachtwoord",
                                      to = new List<EmailAddress>
                                               {
                                                   new EmailAddress(student.Email, string.Format("{0} {1}", student.FirstName, student.LastName))
                                               },
                                  };
                    _mailEngine.Send(msg);

                    return RedirectToAction("List");
                }

                ModelState.AddModelError("", "Studentnummer komt al voor in de database.");
            }

            PrepareStudentModel(model);
            return View(model);
        }

{'fraction_non_alphanumeric': 0.07470267591674926, 'fraction_numerical': 0.00421209117938553, 'mean_word_length': 1.5001548467017654, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 48, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6200789', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1721, 'n_words': 452}