Пример #1
0
        public IHttpActionResult RegisterNewUser([FromBody] UserRegistrationModel userRegistrationModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            CreateAccountRequest accountRequest;

            try
            {
                accountRequest = new CreateAccountRequest(
                    userRegistrationModel.Password,
                    new MailAddress(userRegistrationModel.Mail));
            }
            catch (System.ArgumentException)
            {
                return(BadRequest("Fields must not be empty"));
            }
            int createdUserId;

            try
            {
                createdUserId = _userManager.CreateUser(accountRequest);
            }
            catch (AccountAlreadyExistsException ex)
            {
                return(Content(HttpStatusCode.Conflict, ex.Message));
            }
            _mailingService.SetupEmailConfirmation(createdUserId);
            return(Ok(createdUserId));
        }