Exemple #1
0
        public async Task <ActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                UserIdentityDTO userDto = new UserIdentityDTO
                {
                    Email    = model.Email,
                    Password = model.Password,
                    Address  = model.Address,
                    Name     = model.Name,
                    Role     = new RoleDTO {
                        Name = "user"
                    }
                };                      //TODO MAPPER HERE
                OperationDetails operationDetails = await UserService.Create(userDto);

                if (operationDetails.Succedeed)
                {
                    ClaimsIdentity claim = await UserService.Authenticate(userDto);

                    AuthenticationManager.SignOut();
                    AuthenticationManager.SignIn(new AuthenticationProperties
                    {
                        IsPersistent = true
                    }, claim);

                    _evaluateService.AddUser(claim.GetUserId(), userDto.Name, userDto.Email);
                    return(View("SuccessRegister"));
                }

                ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
            }
            return(View(model));
        }