Пример #1
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, false, false);
                    var userData = new UserData
                    {
                        Id = user.Id,
                        FirstName = model.FirstName,
                        LastName = model.LastName
                    };
                    _uow.UserDataRepository.Insert(userData);
                    _uow.Save();

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Пример #2
0
        public ActionResult ChangeUserData(ChangeUserData model)
        {
            if (ModelState.IsValid)
            {
                var userId = User.Identity.GetUserId();
                var userData = _uow.UserDataRepository.GetById(userId);

                if (userData != null)
                {
                    userData.FirstName = model.FirstName;
                    userData.LastName = model.LastName;

                    _uow.UserDataRepository.Update(userData);
                }
                else
                {
                    userData = new UserData
                    {
                        Id = userId,
                        FirstName = model.FirstName,
                        LastName = model.LastName
                    };

                    _uow.UserDataRepository.Insert(userData);
                }

                _uow.Save();
                return RedirectToAction("Index", "Manage");
            }
            return View(model);
        }