Informedica.GenForm.Mvc3.Controllers.ProductController.DeleteProduct C# (CSharp) Method

DeleteProduct() public method

public DeleteProduct ( String id ) : System.Web.Mvc.ActionResult
id String
return System.Web.Mvc.ActionResult
        public ActionResult DeleteProduct(String id)
        {
            Boolean success;
            var message = String.Empty;
            try
            {
                var product = ProductServices.Get(Guid.Parse(id));
                ProductServices.Delete(product);
                success = true;
            }
            catch (Exception e)
            {
                success = false;
                message = e.ToString();
            }

            return this.Direct(new { success, message });
        }

Usage Example

        public void ReturnAnErrorMessageWhenCannotDeleteProduct()
        {
            _controller = new ProductController();

            var result = _controller.DeleteProduct(Guid.NewGuid().ToString());
            Assert.IsFalse(String.IsNullOrEmpty(ActionResultParser.GetPropertyValue<String>(result, "message")));
        }