Пример #1
0
        /// <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 Controller instance using the helper</param>
        /// <param name="validationErrors">Validation errors, if any, to be returned.</param>
        public IActionResult SimpleCommandResponse(ControllerBase controller, IEnumerable <ValidationError> validationErrors)
        {
            var response = new SimpleCommandResponseData();

            response.Errors  = FormatValidationErrors(validationErrors);
            response.IsValid = !response.Errors.Any();

            return(GetCommandResponse(response, controller));
        }
Пример #2
0
        /// <summary>
        /// Formats a command response wrapping it in a SimpleCommandResponse object and setting
        /// properties based on the presence of validation errors.
        /// </summary>
        /// <param name="validationErrors">Validation errors, if any, to be returned.</param>
        public JsonResult SimpleCommandResponse(IEnumerable <ValidationError> validationErrors)
        {
            var response = new SimpleCommandResponseData();

            response.Errors  = FormatValidationErrors(validationErrors);
            response.IsValid = !response.Errors.Any();

            return(GetCommandResponse(response));
        }
Пример #3
0
        /// <summary>
        /// Returns a formatted 403 error response using the message of the specified exception
        /// </summary>
        /// <param name="controller">The Controller instance using the helper</param>
        /// <param name="ex">The NotPermittedException to extract the message from</param>
        public IActionResult NotPermittedResponse(ControllerBase controller, NotPermittedException ex)
        {
            var response = new SimpleCommandResponseData();

            response.Errors  = new ValidationError[] { new ValidationError(ex.Message) };
            response.IsValid = false;

            return(controller.StatusCode(403, response));
        }
Пример #4
0
        /// <summary>
        /// Returns a formatted 403 error response using the message of the specified exception
        /// </summary>
        /// <param name="ex">The NotPermittedException to extract the message from</param>
        public JsonResult NotPermittedResponse(NotPermittedException ex)
        {
            var response = new SimpleCommandResponseData();

            response.Errors  = new ValidationError[] { new ValidationError(ex.Message) };
            response.IsValid = false;

            var jsonResult = CreateJsonResult(response, 403);

            return(jsonResult);
        }