Exemplo n.º 1
0
        public async Task <IHttpActionResult> UpdatePhone([FromUri] int phoneId, [FromBody] UpdatePhoneRequest createRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            await _phoneService.UpdatePhoneAsync(phoneId, createRequest);

            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent)));
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> AddPhone([FromBody] UpdatePhoneRequest createRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var phone = await _phoneService.CreatePhoneAsync(createRequest);

            var location = string.Format($"/api/phones/{phone.Id}");

            return(Created <StorePhone>(location, phone));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> UpdatePhoneAsync(
            [FromBody] UpdatePhoneRequest model, CancellationToken token)
        {
            var command = new UpdatePhoneCommand(model.UserId, model.NewPhone);

            try
            {
                await _commandBus.DispatchAsync(command, token);
            }
            catch (DuplicateRowException)
            {
                return(Conflict());
            }
            catch (NotFoundException)
            {
                return(NotFound());
            }
            return(Ok());
        }