Ejemplo n.º 1
0
        public async Task <IActionResult> AddAddresses([FromRoute] string id, [FromBody] AddAddressRequest address)
        {
            _logger.LogInformation("Getting user phone");

            try
            {
                var result = await _service.AddAddressAsync(id, address.Line, address.Number, address.PostCode)
                             .ConfigureAwait(false);

                return(StatusCode(result.StatusCode, result.Value));
            }
            catch (Exception e)
            {
                _logger.LogCritical(e, "Error to get user phone");
                return(StatusCode(HttpStatusCode.ServiceUnavailable, "UserService down"));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SetNewAddress(Address address)
        {
            address.Id = Guid.NewGuid();

            ModelState.Clear();
            bool validationResult = TryValidateModel(address);

            if (validationResult)
            {
                bool succedeed = await _userService.AddAddressAsync(address);

                if (!succedeed)
                {
                    return(BadRequest(new { error = "Could not set address" }));
                }

                return(View("Add", address));
            }
            else
            {
                return(View(address));
            }
        }