Exemplo n.º 1
0
        public static T Get <T>(Dictionary <string, string> query = null)
        {
            try
            {
                var queryString = string.Empty;
                var type        = QueryBuilderHelper.GetType <T>(ref query);

                using (var client = QueryBuilderHelper.SetupClient())
                {
                    var stringTask = QueryBuilderHelper.BuildTaskString(query, ref queryString, client, type);
                    var result     = QueryBuilderHelper.CreateObject <T>(stringTask);

                    if (result is IBaseQueryModel model)
                    {
                        model.PagingInfo = HttpResponseToPagingInfo.MapFrom(stringTask.Headers);
                        return((T)model);
                    }

                    return(result);
                }
            }
            catch (Exception ex)
            {
                return((T)Convert.ChangeType(ex.Message, typeof(T)));
            }
        }
Exemplo n.º 2
0
        public static T Find <T>(string id)
        {
            try
            {
                var type = QueryBuilderHelper.GetType <T>();

                using (var client = QueryBuilderHelper.SetupClient())
                {
                    var stringTask = client.GetAsync($"{type}/{id}").Result;
                    return(QueryBuilderHelper.CreateObject <T>(stringTask));
                }
            }
            catch (Exception ex)
            {
                return((T)Convert.ChangeType(ex.Message, typeof(T)));
            }
        }
Exemplo n.º 3
0
        public static T Get <T>(Dictionary <string, string> query = null)
        {
            try
            {
                var queryString = string.Empty;
                var type        = QueryBuilderHelper.GetType <T>(ref query);

                using (var client = QueryBuilderHelper.SetupClient())
                {
                    var stringTask = QueryBuilderHelper.BuildTaskString(query, ref queryString, client, type);
                    return(QueryBuilderHelper.CreateObject <T>(stringTask));
                }
            }
            catch (Exception ex)
            {
                return((T)Convert.ChangeType(ex.Message, typeof(T)));
            }
        }