public async Task <IHttpActionResult> UpdateProduct([FromUri] int id, [FromBody] UpdateProductRequest updateRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var result = await _productService.UpdateProductAsync(id, updateRequest);

                return(this.Ok(result));
            }
            catch (RequestedResourceNotFoundException ex)
            {
                return(this.BadRequest(ex.Message));
            }
            catch (RequestedResourceHasConflictException ex)
            {
                return(this.ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message)));
            }
            catch (Exception)
            {
                return(this.InternalServerError());
            }
        }
예제 #2
0
        public async Task <IHttpActionResult> UpdateProductAsync([FromUri] int id, [FromBody] UpdateProductRequest updateRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id < 1)
            {
                return(BadRequest($"Argument {nameof(id)} must be greater than zero."));
            }

            try
            {
                await _productService.UpdateProductAsync(id, updateRequest);

                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent)));
            }
            catch (RequestedResourceHasConflictException)
            {
                return(Conflict());
            }
            catch (RequestedResourceNotFoundException)
            {
                return(NotFound());
            }
        }
예제 #3
0
        public async Task <IHttpActionResult> UpdateProduct([FromUri] int id, [System.Web.Http.FromBody] UpdateProductRequest updateRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _productService.UpdateProductAsync(id, updateRequest);

            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NoContent)));
        }
예제 #4
0
        public async Task <IActionResult> UpdateProduct(int id, [FromBody] UpdateProductRequest updateRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _productService.UpdateProductAsync(id, updateRequest);

            return(NoContent());
        }