Esempio n. 1
0
        public async Task <ActionResult> AddProduct([FromBody] PostProductRequest productToAdd)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            else
            {
                GetProductDetailResponse response = await _productCommands.Add(productToAdd);

                return(CreatedAtRoute("products#getproductbyid", new { id = response.Id }, response));
            }
        }
        public async Task <ActionResult> AddAProduct([FromBody] PostProductRequest productToAdd)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            else
            {
                // Add it to the domain.
                GetProductDetailsResponse response = await _productCommands.Add(productToAdd);

                // return:
                // 201 Created
                // Location header with the URL of the new thingy.
                // And a copy of what they would get if they followed that URL.
                return(CreatedAtRoute("products#getproductbyid", new { id = response.Id }, response));
            }
        }