Esempio n. 1
0
        public async Task <RestResult <List <PostPresentation> > > LoadDiscussions(DiscussionPayload Payload)
        {
            var response = await provider.LoadDiscussions(Payload);

            RestResult <List <PostPresentation> > result = new RestResult <List <PostPresentation> >();

            result.StatusCode = response.StatusCode;

            foreach (var discussion in response.Data)
            {
                try
                {
                    var data = Mapper.Map <PostPresentation>(discussion);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            result.Data = response.Data
                          .Select(Mapper.Map <Post, PostPresentation>)
                          .ToList();
            return(result);
        }
Esempio n. 2
0
        public async Task <RestResult <List <Post> > > LoadDiscussions(DiscussionPayload Payload)
        {
            var jsonPayload = JsonConvert.SerializeObject(Payload);

            var restResource = "get_discussions_by_trending";

            switch (Payload.Type)
            {
            case DiscussionCategory.Trending:
                restResource = "get_discussions_by_trending";
                break;

            case DiscussionCategory.Promoted:
                restResource = "get_discussions_by_promoted";
                break;

            case DiscussionCategory.New:
                restResource = "get_discussions_by_created";
                break;

            case DiscussionCategory.Hot:
                restResource = "get_discussions_by_hot";
                break;
            }

            var response = await client.GetAsync($"{restResource}?query={jsonPayload}");

            var rawJson = await response.Content.ReadAsStringAsync();

            var list = JsonConvert.DeserializeObject <List <Post> >(rawJson);

            if (list != null)
            {
                foreach (var post in list)
                {
                    post.JsonMetaData = JsonConvert.DeserializeObject <JsonMetaData>(post.JsonMetaDataString);
                }
            }

            return(new RestResult <List <Post> >
            {
                Data = list,
                StatusCode = response.StatusCode
            });
        }