示例#1
0
 public async Task Put(TwitterUserViewModel model)
 {
     try
     {
         await TwitterUserService.Update(model.ToEntity());
     }
     catch { Response.StatusCode = StatusCodes.Status400BadRequest; }
 }
示例#2
0
        public async Task ShouldUpdateTwitterUser()
        {
            userId = await twitterUserService.Add(new TwitterUser { Username = "******", CredibilityScore = 69, });

            var entityToUpdate = (await twitterUserService.GetByFilter(x => x.Username == "TestUser")).FirstOrDefault();

            entityToUpdate.CredibilityScore = 10;
            await twitterUserService.Update(entityToUpdate);

            var result = (await twitterUserService.GetByFilter(x => x.Username == "TestUser")).FirstOrDefault();


            Assert.Equal(10, result.CredibilityScore ?? 0);
        }
        protected async Task <NewsArticleCachedModel> ProcessUrl(string url)
        {
            HttpClient client = new HttpClient();

            ProcessedNewsArticle processedNewsArticle = null;
            var processingUrl            = _processingUnitUrl + "?tweet_url=" + url;
            HttpResponseMessage response = await client.GetAsync(processingUrl);

            if (response.IsSuccessStatusCode)
            {
                var responseStream = await response.Content.ReadAsStreamAsync();

                processedNewsArticle = await JsonSerializer.DeserializeAsync <ProcessedNewsArticle>(responseStream);
            }
            else
            {
                return(null);
            }

            var  user = (await TwitterUserService.GetAsQueriable()).Where(x => x.Username == processedNewsArticle.user).FirstOrDefault();
            Guid userId;

            if (user == null)
            {
                userId = await TwitterUserService.Add(processedNewsArticle.GetTwitterUser());
            }
            else
            {
                userId = user.Id;
                user   = processedNewsArticle.GetTwitterUser(user.Id);
                await TwitterUserService.Update(user);
            }

            var newsArticle = processedNewsArticle.GetAsModel();

            await Add(processedNewsArticle.GetNewsArticle(url, userId));

            return(newsArticle);
        }