Ejemplo n.º 1
0
        public ActionResult Add(PersonRegisterViewModel newAccount)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    PersonBAL balPerson = new PersonBAL();

                    if (balPerson.IsLoginValid(newAccount.Login, db))
                    {
                        if (newAccount.Roles == EnumRoles.Student)
                        {
                            StudentBAL balStudent = new StudentBAL();
                            balStudent.CreateStudentRegistering(newAccount, db);
                        }
                        else
                        {
                            InstructorBAL balInstructor = new InstructorBAL();
                            balInstructor.CreateInstructorRegistering(newAccount, db);
                        }
                        // Move searching of person in an other layer
                        //  getPersonByLogin(newAccount.Login)

                        Session["User"] = balPerson.GetPersonByLogin(newAccount.Login, db);
                        return(RedirectToAction(nameof(HomeController.Index), "Home"));
                    }
                    else
                    {
                        TempData["LoginError"] = "This login already exists";
                        return(RedirectToAction(nameof(AccountController.Register), "Account"));
                    }
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError("Error", "Error");
            }
            return(RedirectToAction(nameof(HomeController.Index), "Home"));
        }