Exemple #1
0
        public static ApiResponseBuilder WithError(this ApiResponseBuilder responseBuilder, Action <Error> errorConfig)
        {
            var error = new Error();

            errorConfig.Invoke(error);
            responseBuilder.AddError(error);
            return(responseBuilder);
        }
Exemple #2
0
        public static ApiResponseBuilder WithLink(this ApiResponseBuilder response, string key, string href, Action <Link> linkConfig)
        {
            var link = new Link {
                Href = href
            };

            linkConfig.Invoke(link);
            response.AddLink(key, link);
            return(response);
        }
Exemple #3
0
        public static ApiResponseBuilder WithResources <T>(this ApiResponseBuilder response, string type, IEnumerable <T> data, Func <T, string> getId)
        {
            var resources = data?.Select(item => new Resource
            {
                Type       = type,
                Id         = getId(item),
                Attributes = item,
            });

            response.DataCollection = resources.ToList();

            return(response);
        }
Exemple #4
0
        public static ApiResponseBuilder WithErrors(this ApiResponseBuilder responseBuilder, ModelStateDictionary modelStateErrors)
        {
            foreach (var validationErrorKvp in modelStateErrors)
            {
                var key = validationErrorKvp.Key;
                var validationErrors = validationErrorKvp.Value.Errors;
                foreach (var validationError in validationErrors)
                {
                    responseBuilder.WithError(error => error.WithCode(key).WithDetail(validationError.ErrorMessage));
                }
            }

            return(responseBuilder);
        }
Exemple #5
0
        public static ApiResponseBuilder WithResource <T>(this ApiResponseBuilder response, string type, T data, string id)
        {
            if (data == null)
            {
                response.Data = new NullResource();
            }
            else
            {
                var resource = new Resource
                {
                    Type       = type,
                    Id         = id,
                    Attributes = data
                };

                response.Data = resource;
            }
            return(response);
        }
Exemple #6
0
 public static ApiResponseBuilder WithMeta(this ApiResponseBuilder response, string key, object value)
 {
     response.AddMeta(key, value);
     return(response);
 }
Exemple #7
0
 public static ApiResponseBuilder WithLink(this ApiResponseBuilder response, string key, string href)
 {
     response.AddLink(key, href);
     return(response);
 }
Exemple #8
0
        public static ApiResponseBuilder WithResources <T>(this ApiResponseBuilder response, IEnumerable <T> data, Func <T, string> getId)
        {
            var type = typeof(T).Name.ToLower();

            return(response.WithResources(type, data, getId));
        }
Exemple #9
0
        public static ApiResponseBuilder WithResource <T>(this ApiResponseBuilder response, T data, string id)
        {
            var type = typeof(T).Name.ToLower();

            return(response.WithResource(type, data, id));
        }