public static ApiResponseBuilder WithError(this ApiResponseBuilder responseBuilder, Action <Error> errorConfig) { var error = new Error(); errorConfig.Invoke(error); responseBuilder.AddError(error); return(responseBuilder); }
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); }
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); }
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); }
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); }
public static ApiResponseBuilder WithMeta(this ApiResponseBuilder response, string key, object value) { response.AddMeta(key, value); return(response); }
public static ApiResponseBuilder WithLink(this ApiResponseBuilder response, string key, string href) { response.AddLink(key, href); return(response); }
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)); }
public static ApiResponseBuilder WithResource <T>(this ApiResponseBuilder response, T data, string id) { var type = typeof(T).Name.ToLower(); return(response.WithResource(type, data, id)); }