Esempio n. 1
0
        public IHttpActionResult PostProducts([FromBody] Dto.Product productDetail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (productDetail == null)
            {
                return(BadRequest("Product detail should not be null."));
            }

            var retrurnProd = _productService.AddProduct(productDetail);

            if (retrurnProd != null && retrurnProd.Id > 0)
            {
                return(Ok(retrurnProd));
            }
            else
            {
                throw new ApiDataException(1002, "Product not saved.", HttpStatusCode.NotFound);
            }
        }
Esempio n. 2
0
        public IHttpActionResult DeleteProducts([FromBody] Dto.Product productDetail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (productDetail == null)
            {
                return(BadRequest("Product detail should not be null."));
            }

            bool isSucess = _productService.DeleteProduct(productDetail);

            if (isSucess)
            {
                return(Ok("Products deleted successfully."));
            }
            else
            {
                throw new ApiDataException(1001, "Product not deleted.", HttpStatusCode.NotFound);
            }
        }