Example #1
0
        public ActionResult Create(CRUDStudentViewModel model)
        {
            string           validationCode = HashUtils.CreateReferralCode();
            var              repository     = new StudentRepository();
            SendConfirmEmail emailSender    = new SendConfirmEmail();

            List <Student> students = repository.GetAll();

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (students.Where(u => u.Email == model.Email).Any())
            {
                ModelState.AddModelError("error_email", "This email is already taken!");
                return(View());
                //return View("Error");
            }
            else if (students.Where(u => u.Username == model.Username).Any())
            {
                ModelState.AddModelError("error_msg", "This username is already taken!");
                return(View());
                // return View("Error");
            }
            else
            {
                Student student = new Student();
                // user.Id = model.Id;
                student.ImgURL           = model.ImgURL;
                student.Username         = model.Username;
                student.Password         = model.Password;
                student.Email            = model.Email;
                student.FirstName        = model.FirstName;
                student.LastName         = model.LastName;
                student.IsEmailConfirmed = false;
                student.ValidationCode   = validationCode;
                student.FacultyNumber    = model.FacultyNumber;
                student.Specialty        = model.Specialty;
                student.GroupId          = model.GroupId;
                student.IsStudent        = model.IsStudent;
                student.IsTeacher        = model.IsTeacher;

                repository.Insert(student);

                sendConfirmEmail.SendConfirmationEmailAsync(student);
            }
            return(RedirectToAction("Index"));
        }
Example #2
0
        public ActionResult Create(UserCreateViewModel model)
        {
            string           validationCode = HashUtils.CreateReferralCode();
            var              repository     = new UserRepository();
            SendConfirmEmail emailSender    = new SendConfirmEmail();

            List <User> users = repository.GetAll();

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (users.Where(u => u.Email == model.Email).Any())
            {
                ModelState.AddModelError("error_email", "This email is already taken!");
                return(View());
                //return View("Error");
            }
            else if (users.Where(u => u.Username == model.Username).Any())
            {
                ModelState.AddModelError("error_msg", "This username is already taken!");
                return(View());
                // return View("Error");
            }
            else
            {
                User user = new User();
                // user.Id = model.Id;
                user.ImgURL           = model.ImgURL;
                user.Username         = model.Username;
                user.Password         = model.Password;
                user.Email            = model.Email;
                user.FirstName        = model.FirstName;
                user.LastName         = model.LastName;
                user.IsAdmin          = model.IsAdmin;
                user.IsEmailConfirmed = false;
                user.ValidationCode   = validationCode;
                user.IsStudent        = model.IsStudent;
                user.IsTeacher        = model.IsTeacher;

                repository.Insert(user);

                sendConfirmEmail.SendConfirmationEmailAsync(user);
            }
            return(RedirectToAction("Index"));
        }