public bool Update(HashtagModel model) // update an existing record { HashtagModel x = Read(model.uid); x = model; return(_db.SaveChanges() == 1); }
/** * This probably should be in the TweetStatModel. * */ public TweetStatModel GetStats() { var Now = DateTimeOffset.Now.ToUnixTimeSeconds(); var PreviousMinute = 60; var PreviousHour = (60 * 60); TwitterAPIDAO dao = new TwitterAPIDAO(); string command = "SELECT Count(*) AS total"; command += ", (SELECT SUM(`LIKE`) FROM tweets) AS 'totalLikes'"; command += ", (SELECT SUM(`reTweet`) FROM tweets) AS 'totalRetweets'"; command += ", (SELECT COUNT(*) FROM tweets WHERE hasEmoji = 1) AS 'totalEmojis'"; command += ", (SELECT COUNT(*) FROM tweets WHERE hasImage = 1) AS 'totalImages'"; command += ", (SELECT COUNT(*) FROM tweets WHERE hasUrl = 1) AS 'totalUrls'"; command += ", (SELECT COUNT(*) FROM tweets WHERE `date` >= (SELECT MAX(`date`) FROM tweets) - 1) AS 'lastSecond'"; command += ", (SELECT COUNT(*) FROM tweets WHERE `date` >= (SELECT MAX(`date`) FROM tweets) - " + PreviousMinute + ") AS 'lastMinute'"; command += ", (SELECT COUNT(*) FROM tweets WHERE `date` >= (SELECT MAX(`date`) FROM tweets) - " + PreviousHour + ") AS 'lastHour'"; command += "FROM tweets"; TweetStatModel tweetStats = dao.GetSingleObject(command); tweetStats.Emojis = EmojiModel.GetEmojis(); tweetStats.Hashtags = HashtagModel.GetHashtags(); tweetStats.Languages = LanguageModel.GetLanguages(); tweetStats.Mentions = MentionModel.GetMentions(); tweetStats.Urls = UrlModel.GetUrls(); return(tweetStats); }
public HashtagModel GetExtractPost(string posttext) { /* * Örnek : Bugün ##Misaş ve #Bi#m'de Mükemmel İndirimler var... */ HashtagModel hashtagmodel = new HashtagModel(); bool ishashtag = false; string bulunantag = String.Empty; List <string> hashtag = new List <string>(); string orginal = posttext; List <string> postlist = posttext.Split(' ').ToList(); foreach (var item in postlist) { if (ishashtag == false) { if (item.StartsWith("#")) { int count = item.Count(sa => sa.ToString() == "#"); char[] resultTag = new char[item.Length]; bulunantag = item; var filter = item; if (count > 1) { for (int i = 1; i < bulunantag.Length; i++) { if (bulunantag[i].ToString() != "#") { resultTag[i] = bulunantag[i]; } else { resultTag[i] = ' '; } } resultTag[0] = '#'; bulunantag = new string(resultTag); bulunantag = bulunantag.Replace(" ", ""); posttext = posttext.Replace(item, bulunantag); } ishashtag = true; } } else if (ishashtag == true) { var filter = item; filter = filter.Replace("#", ""); posttext = posttext.Replace(item, filter); } } hashtagmodel.HashTag = bulunantag; hashtagmodel.OnlyText = posttext; return(hashtagmodel); }
public void ToDbItem_ItemHasExpectedAttributeCount() { PhotoId photoId = new Guid("d3eaa102-6ce7-4cbe-823d-9ee1d046e1b6"); string hashtagText = "#hashtag"; var hashtag = new HashtagModel { PhotoId = photoId, Hashtag = hashtagText }; var dbItem = Mappers.Hashtag.ToDbItem(hashtag); dbItem.Count.ShouldBe(3); }
public void ToDbItem_AttributesHaveExpectedValues() { PhotoId photoId = new Guid("d3eaa102-6ce7-4cbe-823d-9ee1d046e1b6"); string hashtagText = "#hashtag"; DateTimeOffset createdTime = new DateTimeOffset(2019, 9, 29, 8, 4, 19, 32, TimeSpan.Zero); var hashtag = new HashtagModel { PhotoId = photoId, Hashtag = hashtagText, CreatedTime = createdTime }; var dbItem = Mappers.Hashtag.ToDbItem(hashtag); dbItem[FieldMappings.Hashtag.HastagId].S.ShouldBe("hash|hashtag"); dbItem[FieldMappings.Hashtag.PhotoId].S.ShouldBe(photoId.ToDbValue()); dbItem[FieldMappings.Hashtag.CreatedTime].S.ShouldBe("2019-09-29T08:04:19,032Z"); }
public async Task <IEnumerable <PhotoModel> > GetPhotosByHashtag(UserId currentUserId, HashtagModel hashtag) { logWriter.LogInformation($"{nameof(GetPhotosByHashtag)}({nameof(hashtag)} = '{hashtag.Hashtag}')"); var hashtagId = Mappers.Hashtag.ToDbKey(hashtag)[FieldMappings.Hashtag.HastagId]; QueryRequest request = new QueryRequest { TableName = tableName, KeyConditionExpression = $"{FieldMappings.PartitionKey} = :hashtagId", ExpressionAttributeValues = new Dictionary <string, AttributeValue> { { ":hashtagId", hashtagId } }, ReturnConsumedCapacity = ReturnConsumedCapacity.INDEXES }; var response = await dynamoDbCore.Query(request, Mappers.HashtagPhoto); var result = new ConcurrentDictionary <PhotoId, PhotoModel>(); foreach (var photo in response.Select(x => x.Photo)) { result.TryAdd(photo.PhotoId, photo); } await AddLikeDataForUser(currentUserId, result); return(result.Values); }
public bool Create(HashtagModel model) // add a new record to the DBMS { _db.Hashtags.Update(model); return(_db.SaveChanges() == 1); }
public JsonResult <HashtagModel> ExtractPost([FromBody] HashtagModel post) { return(Json(_tagbl.GetExtractPost(post.OnlyText))); }