コード例 #1
0
        public async Task <IHttpActionResult> AddProduct([System.Web.Http.FromBody] UpdateProductRequest createRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var product = await _productService.CreateProductAsync(createRequest);

            var location = string.Format("/api/products/{0}", product.Id);

            return(Created <Product>(location, product));
        }
コード例 #2
0
        public async Task <IHttpActionResult> AddProduct([FromBody] UpdateProductRequest createRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var product = await _productService.CreateProductAsync(createRequest);

            var location = $"/api/products/{product.Id}";

            return(Created(location, product));
        }
コード例 #3
0
        public async Task <IHttpActionResult> AddProductAsync([FromBody] UpdateProductRequest createRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var product = await _productService.CreateProductAsync(createRequest);

                var location = string.Format("/api/products/{0}", product.Id);
                return(Created <Product>(location, product));
            }
            catch (RequestedResourceHasConflictException)
            {
                return(Conflict());
            }
        }
コード例 #4
0
        public async Task <IHttpActionResult> AddProduct([FromBody] UpdateProductRequest createRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var product = await _productService.CreateProductAsync(createRequest);

                var location = string.Format("/api/products/{0}", product.Id);
                return(Created <Product>(location, product));
            }
            catch (RequestedResourceHasConflictException ex)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message)));
            }
            catch (Exception)
            {
                return(this.InternalServerError());
            }
        }