Example #1
0
        public static HttpResponseMessage BuildApiResponse(HttpRequestMessage request, HttpStatusCode statusCode, object result = null, List <ErrorStateResponse> errorMessage = null)
        {
            var resultObj = new ApiHttpResponse(statusCode, result, errorMessage);
            var response  = request.CreateResponse(statusCode, resultObj);

            response.Content = response.Content;
            return(response);
        }
Example #2
0
        public static HttpResponseMessage BuildApiResponse(HttpRequestMessage request, HttpStatusCode statusCode, object result = null, List <ErrorStateResponse> errorMessage = null, List <Header> header = null)
        {
            var resultObj = new ApiHttpResponse(statusCode, result, errorMessage);
            var response  = request.CreateResponse(statusCode, resultObj);

            if (header != null)
            {
                foreach (var head in header)
                {
                    response.Headers.Add(head.HeaderName, head.HeaderValue);
                }
            }
            return(response);
        }
Example #3
0
        public static HttpResponseMessage BuildApiResponse(HttpRequestMessage request, HttpStatusCode statusCode, object result = null, List <ErrorStateResponse> errorMessage = null, JsonSerializerSettings settings = null)
        {
            string serializedResult = JsonConvert.SerializeObject(result, settings);

            if (result != null)
            {
                if (result.GetType().IsGenericType)
                {
                    result = JArray.Parse(serializedResult);
                }
                else
                {
                    result = JObject.Parse(serializedResult);
                }
            }
            var resultObj = new ApiHttpResponse(statusCode, result, errorMessage);
            var response  = request.CreateResponse(statusCode, resultObj);

            return(response);
        }