public IActionResult <List <ShoutViewModel> > Feed(HttpResponse response, HttpSession session) { if (this.signInManager.IsAuthenticated(session)) { var user = this.data.LoginRepository.FindUserByLogin(session.Id); List <string> userFollowersUsernames = new List <string>(); foreach (var userFollower in user.Following) { userFollowersUsernames.Add(userFollower.Username); } var shouts = this.data.ShoutRepository.UpdateAndGetAllShouts(s => userFollowersUsernames.Contains(s.Author.Username)); var shoutViewModels = new List <ShoutViewModel>(); foreach (var shout in shouts) { var shoutViewModel = new ShoutViewModel() { Author = shout.Author, Content = shout.Content, PostedForTime = Extensions.CalculateTimeSincePost(shout.PostedOn) }; shoutViewModels.Add(shoutViewModel); } this.data.SaveChanges(); return(this.View(shoutViewModels)); } this.Redirect(response, "/home/login"); return(null); }
public IActionResult <List <ShoutViewModel> > FeedSigned(HttpResponse response, HttpSession session) { if (this.signInManager.IsAuthenticated(session)) { var shouts = this.data.ShoutRepository.UpdateAndGetAllShouts(); var shoutViewModels = new List <ShoutViewModel>(); foreach (var shout in shouts) { var shoutViewModel = new ShoutViewModel() { Author = shout.Author, Content = shout.Content, PostedForTime = Extensions.CalculateTimeSincePost(shout.PostedOn) }; shoutViewModels.Add(shoutViewModel); } this.data.SaveChanges(); return(this.View(shoutViewModels)); } else { this.Redirect(response, "/home/feed"); return(null); } }
public IActionResult <UserProfileViewModel> Profile(HttpSession session, int id) { var currentUser = this.data.LoginRepository.FindUserByLogin(session.Id); var user = this.data.UsersRepository.GetById(id); var shoutsByUser = this.data.ShoutRepository.Find(s => s.Author.Id == user.Id); string followStatus = string.Empty; string followOption = string.Empty; bool isFollowing = currentUser.Following.Contains(user); if (isFollowing) { followStatus = "danger"; followOption = "Unfollow"; } else { followStatus = "success"; followOption = "Follow"; } var userProfileModel = new UserProfileViewModel() { Username = user.Username, FollowOption = followOption, FollowStatus = followStatus }; foreach (var userShout in shoutsByUser) { var shoutViewModel = new ShoutViewModel() { Author = user, Content = userShout.Content, PostedForTime = Extensions.CalculateTimeSincePost(userShout.PostedOn) }; userProfileModel.Shouts.Add(shoutViewModel); } return(this.View(userProfileModel)); }