public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemple #2
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                bool status = _accountService.ValidateRegistration(model.Email);
                if (status)
                {
                    FormsAuthentication.SetAuthCookie(model.Email, false);
                    _user.Password = model.Password;
                    _user.Email = model.Email;
                    _user.Role = model.Role;
                    _accountService.SaveUser(_user);
                    if (model.Role.Equals("Doctor"))
                    {
                        var doctor = new Doctor();
                        doctor.LastName = model.LastName;
                        doctor.FirstName = model.FirstName;
                        doctor.MobileNumber = model.MobileNumber;
                        _doctorService.SaveProfile(doctor, model.Email);
                        _doctorService.SaveAddress(new Address(), model.Email);
                        _doctorService.SaveSchedule(new Schedule(), model.Email);
                    }
                    Session["Success"] = "Registration Successful";

                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "User Name already exists");
                    Session["Error"] = "Registration Failure";
                    return RedirectToAction("Register", "Account");
                }

            }
            return RedirectToAction("Register", "Account");
        }