public ActionResult JsonRegister(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(model.UserName, model.Password, model.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false);
                    return Json(new { success = true });
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed
            return Json(new { errors = GetErrorsFromModelState() });
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var command = new UserCreateCommand
                {
                    Email = model.Email,
                    UserName = model.UserName,
                    Password = model.Password,
                    CommandCompanyId = model.CommandCompanyId,
                    CommandByUser = model.CommandByUser,
                    CommandWhen = model.CommandWhen
                };

                var user = new User();
                user.Update(command);

                RavenSession.Advanced.UseOptimisticConcurrency = true;
                RavenSession.Store(user);
                RavenSession.Store(UniqueUser.FromUser(user));
                RavenSession.SaveChanges();
                return RedirectToAction("Register");
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }