/// <summary> /// Returns a formatted 403 error response using the message of the specified exception /// </summary> /// <param name="controller">The ApiController instance using the helper</param> /// <param name="ex">The NotPermittedException to extract the message from</param> public IHttpActionResult NotPermittedResponse(ApiController controller, NotPermittedException ex) { var response = new SimpleCommandResponseData(); response.Errors = new ValidationError[] { new ValidationError(ex.Message) }; response.IsValid = false; return(new NegotiatedContentResult <SimpleCommandResponseData>(HttpStatusCode.Forbidden, response, controller)); }
/// <summary> /// Formats a command response wrapping it in a SimpleCommandResponse object and setting /// properties based on the presence of validation errors. /// </summary> /// <param name="controller">The ApiController instance using the helper</param> /// <param name="validationErrors">Validation errors, if any, to be returned.</param> public IHttpActionResult SimpleCommandResponse(ApiController controller, IEnumerable <ValidationError> validationErrors) { var response = new SimpleCommandResponseData(); response.Errors = FormatValidationErrors(validationErrors); response.IsValid = !response.Errors.Any(); var responseCode = response.IsValid ? HttpStatusCode.OK : HttpStatusCode.BadRequest; return(new NegotiatedContentResult <SimpleCommandResponseData>(responseCode, response, controller)); }