Example #1
0
        /// <summary>
        /// Generic method for getting API client request for single source
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="apiMethodwithParameter"></param>
        /// <returns></returns>
        protected List <T> GetManyFromAPI <T>(string apiMethodwithParameter) where T : class
        {
            WebApiResult <IEnumerable <T> > result = null;

            try
            {
                ApiHttpClient <T> httpClient = new ApiHttpClient <T>(ServiceUrl, false);
                SetToken(httpClient);
                result = httpClient.GetManyAsync(apiMethodwithParameter).Result;

                if (!result.HasError)
                {
                    if (result.Data != null)
                    {
                        return(result.Data.ToList());
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    Error(apiMethodwithParameter, result.ErrorMessages);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
            }
            return(null);
        }