public void AddTagTweetMapping(HashTagTweetMapDTO hashTagTweetMapDTO) { try { HashTagTweetMap hashTagTweetMap = new HashTagTweetMap(); hashTagTweetMap.TweetId = hashTagTweetMapDTO.TweetId; hashTagTweetMap.HashTagId = hashTagTweetMapDTO.HashTagId; db.HashTagTweetMaps.Add(hashTagTweetMap); Save(); } catch (Exception) { Console.WriteLine("Exception in database handling."); } }
public void DeleteTagTweetMapping(HashTagTweetMapDTO hashTagTweetMapDTO) { try { //get the hashTagMapping object from the database var hashTagTweetMapObj = db.HashTagTweetMaps .Where(x => x.TweetId == hashTagTweetMapDTO.TweetId && x.HashTagId == hashTagTweetMapDTO.HashTagId).FirstOrDefault(); if (hashTagTweetMapObj != null) { db.HashTagTweetMaps.Remove(hashTagTweetMapObj); Save(); } } catch (Exception) { Console.WriteLine("Error in database connectivity"); } }
// used to delete a particular tweet from the databse public TweetDTO DeleteTweet(TweetDTO tweetDTO) { TweetDTO tweet = objDb.GetByID(tweetDTO.TweetId); //get all the hashtags contain in that tweet IList <string> hashTags = GetHashTags(tweet.TweetContent); //for each hashtag update the mapping Table first and then update the hashtag table foreach (string hashTag in hashTags) { int hashTagId = objHashTagDb.GetHashTagId(hashTag); // update the hasshTagTweetMapping Table based on the hashtagId and the tweetId HashTagTweetMapDTO hashTagTweetMapDTO = new HashTagTweetMapDTO(); hashTagTweetMapDTO.TweetId = tweetDTO.TweetId; hashTagTweetMapDTO.HashTagId = hashTagId; objTagTweetMappingDb.DeleteTagTweetMapping(hashTagTweetMapDTO); objHashTagDb.UpdateHashTag(hashTag); } objDb.Delete(tweet.TweetId); return(tweet); }
//Adding Tweet public TweetDTO AddTweet(TweetDTO tweetDTO) { TweetDTO outTweetDTo = objDb.AddTweet(tweetDTO); IList <string> hashTags = GetHashTags(tweetDTO.TweetContent); foreach (string hashTag in hashTags) { int hashTagId = objDb.AddHashTag(hashTag); HashTagTweetMapDTO hashTagTweetMapDTO = new HashTagTweetMapDTO(); hashTagTweetMapDTO.TweetId = outTweetDTo.TweetId; hashTagTweetMapDTO.HashTagId = hashTagId; AddTagTweetMapping(hashTagTweetMapDTO); } return(outTweetDTo); }
public void AddTagTweetMapping(HashTagTweetMapDTO hashTagTweetMapDTO) { objDb.AddTagTweetMapping(hashTagTweetMapDTO); }