public void FollowUser(FOLLOWING following) { TwitterDBContext twitterDBContext = new TwitterDBContext(); twitterDBContext.FOLLOWINGs.Add(following); twitterDBContext.SaveChanges(); }
public void Signup(PERSON pObj) { TwitterDBContext twitterDBContext = new TwitterDBContext(); twitterDBContext.People.Add(pObj); twitterDBContext.SaveChanges(); }
public async Task <IActionResult> MyFile(IFormFile uploadedFile) { var currentUser = _userManager.FindByNameAsync(User.Identity.Name); if (uploadedFile != null) { // путь к папке Files string path = "/Files/" + uploadedFile.FileName; // сохраняем файл в папку Files в каталоге wwwroot using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create)) { await uploadedFile.CopyToAsync(fileStream); } FileModel file = new FileModel { Name = uploadedFile.FileName, Path = path }; _context.Files.Add(file); _context.SaveChanges(); } return(RedirectToAction("Index", "Profile", new { userName = currentUser })); }
public void DeactivateAccount(string id) { TwitterDBContext twitterDBContext = new TwitterDBContext(); var result = twitterDBContext.People.Where(m => m.user_id == id).First(); result.active = false; twitterDBContext.SaveChanges(); }
public void UnFollowUser(string id, string user) { TwitterDBContext twitterDBContext = new TwitterDBContext(); var delObj = twitterDBContext.FOLLOWINGs.Where(m => m.user_id == user && m.following_id == id).First(); twitterDBContext.FOLLOWINGs.Remove(delObj); twitterDBContext.SaveChanges(); }
public void EditProfile(PERSON pObj) { TwitterDBContext twitterDBContext = new TwitterDBContext(); var person = twitterDBContext.People.Where(m => m.user_id == pObj.user_id).FirstOrDefault(); person.fullName = pObj.fullName; person.email = pObj.email; person.password = pObj.password; twitterDBContext.SaveChanges(); }
public Profile NewTweet(Tweet tweet, string user) { TwitterDBContext twitterDBContext = new TwitterDBContext(); Assignment1.TWEET tObj = new TWEET(); tObj.user_id = user; tObj.message = tweet.message; tObj.created = DateTime.Now; twitterDBContext.TWEETs.Add(tObj); twitterDBContext.SaveChanges(); var person = twitterDBContext.People.Where(m => m.user_id == user).FirstOrDefault(); Profile pObj = new Profile(); var selfTweets = person.TWEETs; pObj.selfTweets = new List <Tweet>(); foreach (var item in selfTweets) { pObj.selfTweets.Add(new Tweet { created = item.created, message = item.message, user_id = item.user_id }); } var following = person.FOLLOWINGs1; pObj.following = new List <Person>(); foreach (var item in following) { pObj.following.Add(new Person { user_id = item.following_id }); } pObj.allTweets = new List <Tweet>(); pObj.allTweets.AddRange(pObj.selfTweets); foreach (var item in pObj.following) { var followingTweet = twitterDBContext.TWEETs.Where(m => m.user_id == item.user_id); foreach (var value in followingTweet) { pObj.allTweets.Add(new Tweet { created = value.created, message = value.message, user_id = value.user_id }); } } pObj.allTweets = pObj.allTweets.OrderByDescending(m => m.created).ToList(); return(pObj); }
public Profile DeleteTweet(Tweet tweet, string user) { TwitterDBContext twitterDBContext = new TwitterDBContext(); var tObj = twitterDBContext.TWEETs.Where(m => m.tweet_id == tweet.tweet_id).FirstOrDefault(); twitterDBContext.TWEETs.Remove(tObj); twitterDBContext.SaveChanges(); var person = twitterDBContext.People.Where(m => m.user_id == user).FirstOrDefault(); Profile pObj = new Profile(); var selfTweets = person.TWEETs; pObj.selfTweets = new List <Tweet>(); foreach (var item in selfTweets) { pObj.selfTweets.Add(new Tweet { created = item.created, message = item.message, user_id = item.user_id }); } pObj.selfTweets = pObj.selfTweets.OrderByDescending(m => m.created).ToList(); return(pObj); }