Пример #1
0
        public async Task <IActionResult> Register([FromBody] Client.Users.UserRegistrationInfo registrationInfo,
                                                   CancellationToken cancellationToken)
        {
            if (registrationInfo == null)
            {
                var error = ServiceErrorResponses.BodyIsMissing("UserRegistrationInfo");
                return(this.BadRequest(error));
            }

            User result;
            var  creationInfo = new UserCreationInfo(registrationInfo.Login,
                                                     Authenticator.HashPassword(registrationInfo.Password), registrationInfo.FirstName,
                                                     registrationInfo.LastName, registrationInfo.Email, registrationInfo.Phone);

            try
            {
                result = await userRepository.CreateAsync(creationInfo, cancellationToken);
            }
            catch (UserDuplicationException)
            {
                var error = ServiceErrorResponses.ConflictLogin(creationInfo?.Login);
                return(this.Conflict(error));
            }

            var clientUser = UserConverter.Convert(result);

            return(this.Ok(clientUser));
        }