public TweetEngagementVM GetUserRetweet(int userID, int tweetID) { Retweets retweet = db.Retweets.Where(x => x.TweetID == tweetID && x.UserID == userID).SingleOrDefault(); if (retweet != null) { return new TweetEngagementVM { tweetID = tweetID, userID = userID, engaged = true } } ; else { return new TweetEngagementVM { tweetID = tweetID, userID = userID, engaged = false } }; } }
public TweetEngagementVM PostRetweets(int tweetID, int userID) { Retweets retweet = db.Retweets.Where(x => x.TweetID == tweetID && x.UserID == userID).SingleOrDefault(); if (retweet == null) { db.Retweets.Add(new Retweets { TweetID = tweetID, UserID = userID, RetweetTime = DateTime.Now }); db.SaveChanges(); return(new TweetEngagementVM { tweetID = tweetID, userID = userID, engaged = true }); } else { db.Retweets.Remove(retweet); db.SaveChanges(); return(new TweetEngagementVM { tweetID = tweetID, userID = userID, engaged = false }); } }
public async Task AddRetweet(Entry entry, HttpClient client) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token); var response = await client.PostAsync($"api/entries/{entry.Id}/retweet", null); if (response.StatusCode == HttpStatusCode.OK) { Retweets.Add(entry); entry.RetweetCount++; } }
public async Task RemoveRetweet(Entry entry, HttpClient client) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token); var response = await client.DeleteAsync($"api/entries/{entry.Id}/remove-retweet"); if (response.StatusCode == HttpStatusCode.OK) { if (Retweets.Any(e => e.Id == entry.Id)) { Retweets.Remove(entry); } entry.RetweetCount--; } }
public IActionResult Retweet(Retweets rt, User user, Tweets tweets) { ViewBag.Name = HttpContext.Session.GetString("Name"); ViewBag.UserName = HttpContext.Session.GetString("UserName"); ViewBag.Password = HttpContext.Session.GetString("Password"); User rtlenen = (from s in _context.Users where ("@" + s.UserName) == tweets.UserName select s).FirstOrDefault(); User rtleyen = (from s in _context.Users where s.UserName == HttpContext.Session.GetString("UserName") select s).FirstOrDefault(); tweets = (from s in _context.Tweets where s.TweetID == tweets.TweetID select s).FirstOrDefault(); tweets.Retweets++; Tweets newtweet = new Tweets(); newtweet.ProfilePicture = tweets.ProfilePicture; newtweet.Likes = tweets.Likes; newtweet.Retweets = tweets.Retweets; newtweet.tweet = tweets.tweet; newtweet.UserName = tweets.UserName; newtweet.UsName = tweets.UsName; newtweet.User = rtleyen; ViewBag.Rt = rtleyen.UserName + " retweetledi"; rt.KullanıcıId = rtleyen.UserID; _context.Add(rt); _context.Add(newtweet); _context.SaveChanges(); ViewBag.UserName = "******" + HttpContext.Session.GetString("UserName"); return(RedirectToAction("Index")); }