Пример #1
0
        // POST api/product
        public IHttpActionResult Post([FromBody]Product product)
        {
            try
            {
                if (product == null)
                    return BadRequest("Product can not be null");

                if (!ModelState.IsValid) return BadRequest(ModelState);

                var productReppstory = new ProductRepository();

                var newProduct = productReppstory.Save(product);

                if (newProduct == null)
                    return Conflict();

                return Created(Request.RequestUri + newProduct.ProductId.ToString(), newProduct);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }
Пример #2
0
        // PUT api/product/5
        public IHttpActionResult Put(int id, [FromBody]Product product)
        {
            try
            {
                if (product == null) return BadRequest("Product can not be null");

                if (!ModelState.IsValid) return BadRequest(ModelState);

                var productReppstory = new ProductRepository();
                var updatedProduct = productReppstory.Save(id, product);
                if (updatedProduct == null) NotFound();

                return Ok("Product Updated");
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }