Example #1
0
        public Task <HttpResponseMessage> HttpGet(LibraryBooksRequest libraryBooksRequest)
        {
            _client.DefaultRequestHeaders.Accept.Clear();
            _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            libraryBooksRequest.RequestHeaders.ToList().ForEach(requestHeader =>
            {
                _client.DefaultRequestHeaders.Add(requestHeader.Name, requestHeader.Value);
            });
            return(_client.GetAsync(libraryBooksRequest.RequestUrl));
        }
Example #2
0
        protected LibraryBooksRequest GenerateLibraryBookRequest(BookFilter bookFilter)
        {
            try
            {
                LibraryBooksRequest libraryBooksRequest = new LibraryBooksRequest();
                libraryBooksRequest.RequestUrl = "http://localhost:2320/Books";

                if (bookFilter != null)
                {
                    List <string> urlParamerters = new List <string>();

                    if (!string.IsNullOrWhiteSpace(bookFilter.ISBN))
                    {
                        urlParamerters.Add(string.Format("ISBN={0}", bookFilter.ISBN));
                    }
                    if (!string.IsNullOrWhiteSpace(bookFilter.Title))
                    {
                        urlParamerters.Add(string.Format("Title={0}", bookFilter.Title));
                    }
                    if (!string.IsNullOrWhiteSpace(bookFilter.AuthorName))
                    {
                        urlParamerters.Add(string.Format("AuthorName={0}", bookFilter.AuthorName));
                    }
                    if (!string.IsNullOrWhiteSpace(bookFilter.Genre))
                    {
                        urlParamerters.Add(string.Format("Genre={0}", bookFilter.Genre));
                    }

                    libraryBooksRequest.RequestUrl = urlParamerters.Count() > 0 ?
                                                     string.Format("{0}?{1}", libraryBooksRequest.RequestUrl, string.Join("&", urlParamerters))
                        : libraryBooksRequest.RequestUrl;
                }

                libraryBooksRequest.RequestHeaders = new List <RequestHeader>();

                return(libraryBooksRequest);
            }
            catch (Exception ex)
            {
                //TODO: Log this the exception information along with the method details to the database for Error tracing
                //Allowing the exception be rethrown so that LOG4NET can log there is a problem on the api end point
                return(null);
            }
        }