Пример #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var registerService = AppHostBase.Resolve<RegistrationService>();
                registerService.RequestContext = System.Web.HttpContext.Current.ToRequestContext();

                try
                {
                    // Attempt to register the user
                    registerService.Post(new Registration
                                             {
                                                 AutoLogin = true,
                                                 DisplayName = model.DisplayName,
                                                 Email = model.Email,
                                                 FirstName = model.FirstName,
                                                 LastName = model.LastName,
                                                 Password = model.Password,
                                                 UserName = model.Email
                                             });

                    return RedirectToAction("Index", "Home");
                }
                catch (ValidationException ex)
                {
                    var errorMsg = ex.Message;
                    var error = ex.Errors.FirstOrDefault();
                    if (error != null && error.ErrorMessage != null)
                    {
                        errorMsg = error.ErrorMessage;
                    }

                    ModelState.AddModelError("", errorMsg);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Пример #2
0
 public ActionResult Register()
 {
     var model = new RegisterModel();
     return View(model);
 }