private static RestResult CreateRestResultWhenSuccessful <T>(DispatcherResponse <T> data, object value, HttpStatusCode statusCode) where T : BaseResponseType
        {
            var warnings    = Enumerable.Empty <ValidationOutcome>();
            var infos       = Enumerable.Empty <ValidationOutcome>();
            var errors      = Enumerable.Empty <ValidationOutcome>();
            var ruleResults = data.Data.RuleResults;

            if (ruleResults != null)
            {
                warnings = ruleResults
                           .Where(rl => rl.ValidationOutcome.OutcomeStatus.Equals(BusinessRule.OutcomeStatus.Warning.ToString()))
                           .Select(p => p.ValidationOutcome).ToList();
                infos = ruleResults
                        .Where(rl => rl.ValidationOutcome.OutcomeStatus.Equals(BusinessRule.OutcomeStatus.Info.ToString()))
                        .Select(p => p.ValidationOutcome).ToList();

                errors = ruleResults
                         .Where(rl => rl.ValidationOutcome.OutcomeStatus.Equals(BusinessRule.OutcomeStatus.Error.ToString()))
                         .Select(p => p.ValidationOutcome).ToList();
            }

            var restContent = new RestContent(value,
                                              errors.Any() ? errors : null, warnings.Any() ? warnings : null, infos.Any() ? infos : null);

            return(new RestResult(restContent, statusCode));
        }
示例#2
0
        public async Task <RestResult> BuildGeneric(HttpStatusCode statusCode, string message = "", string description = "")
        {
            if (statusCode == HttpStatusCode.OK && message == "")
            {
                return(new RestResult((object)null));
            }

            var restContent = RestContent.CreateWithErrors(new[]
            {
                new ValidationOutcome
                {
                    OutcomeStatus = "Error",
                    Code          = "Generic",
                    Message       = message,
                    Description   = description
                }
            });

            return(new RestResult(restContent, statusCode));
        }
 private static RestResult CreateRestResultWhenFailed(ExceptionResponse exception)
 {
     return(new RestResult(RestContent.CreateWithGenericError(exception.ErrorMessage), exception.HttpStatusCode));
 }