Ejemplo n.º 1
0
        public async Task <IActionResult> Register([FromBody] RegisterRequest request)
        {
            var validationResult = _registerValidator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors.First().ErrorMessage));
            }
            var result = await _bus.Send(new RegisterCommand(request.UserName, request.Password));

            return(result.Match <IActionResult>(
                       some: x => Ok(new UserResponse(x.Id, x.UserName)),
                       none: () => BadRequest()));
        }
Ejemplo n.º 2
0
        public async Task <RegisterResponse> Register([FromBody] RegisterRequest request)
        {
            var result = new RegisterResponse {
                Succeed = false, Errors = new List <string>()
            };

            var validator        = new RegisterRequestValidator();
            var validationResult = validator.Validate(request);

            if (validationResult.IsValid)
            {
                result = await _authService.RegisterAsync(request);
            }
            else
            {
                result.Errors.Add("Invalid data!");
            }

            return(result);
        }