예제 #1
0
        /// <summary>
        /// Gets a list of listings ids and query reddit for the data.
        /// We need this since we DON'T store any reddit information.
        /// For tags we just store the post_id and then bulk fetch it when users want to gets his flags
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        private async Task <IEnumerable <PostFlagModel> > getRedditPostsByName(TagRelationship[] tags)
        {
            var retval = new List <PostFlagModel>();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(redditEndpointUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                //I ASSUME ALL POSTS ARE LITINGS HENCE FROM TYPE T3
                var posts_with_affix = tags.Select(x => "t3_" + x.postId);
                var queryString      = string.Join(",", posts_with_affix);

                HttpResponseMessage response = await client.GetAsync(string.Format("/by_id/{0}.json", queryString));

                if (response.IsSuccessStatusCode)
                {
                    var res = await response.Content.ReadAsAsync <RedditResponse>();

                    foreach (var pd in res.data.children)
                    {
                        var flag_post = new PostFlagModel(pd.data);

                        //match flag name to returned data
                        flag_post.tag_name = tags.Where(t => t.postId == pd.data.id).Single().name;
                        retval.Add(flag_post);
                    }
                }
            }

            return(retval);
        }
예제 #2
0
        public async Task <bool> SaveNewFlag(PostFlagModel model)
        {
            //var convertedLeads = await _context.ConvertedLeads.SingleAsync(x => x.Id.Equals(model.UserId));
            //_log.Info($"converted lead - {JsonConvert.SerializeObject(convertedLeads)}");

            //var properties = JsonConvert.DeserializeObject<dynamic>(convertedLeads.Properties);
            //properties.Flag = model.Flag;
            //convertedLeads.Properties = JsonConvert.SerializeObject(properties);
            //var result = await _context.SaveChangesAsync();
            //_log.Info($"result - {result}");

            //return result == 1;
            // TODO: fix
            return(await Task.FromResult(true));
        }