public ActionResult Dislike(FormCollection collection) { string postId = collection["postId"]; if (postId.IsNullOrWhiteSpace()) { return(View("Error")); } // Find out if user has disliked, liked or done nothing and like the status according to that var pid = Int32.Parse(postId); var likedislikeService = new LikeDislikeService(DbContext); var ld = likedislikeService.GetLikeDislike(User.Identity.GetUserId(), pid); if (ld != null) { if (ld.Like) // Switch from like to dislike { DbContext.LikesDislikes.Remove(ld); DbContext.LikesDislikes.Add(new LikeDislike() { PostId = pid, UserId = User.Identity.GetUserId(), Like = false, Dislike = true }); } else if (ld.Dislike) // UnDislike { DbContext.LikesDislikes.Remove(ld); } } else // Dislike { DbContext.LikesDislikes.Add(new LikeDislike() { PostId = pid, UserId = User.Identity.GetUserId(), Like = false, Dislike = true }); } DbContext.SaveChanges(); // Fill in the json var postService = new PostService(DbContext); var json = new { likes = postService.GetPostsLikes(pid), dislikes = postService.GetPostsDislikes(pid), action = ld }; return(Json(json, JsonRequestBehavior.AllowGet)); }
public ActionResult Details(int?id) { if (!id.HasValue) { return(View("Error")); } int grpId = id.Value; // Getting group information var userService = new UserService(DbContext); var groupService = new GroupService(DbContext); var group = groupService.GetGroupById(grpId); var myGroup = new GroupDetailViewModel() { Name = group.Name, AdminId = group.AdminID, GroupId = grpId, Members = new List <UserViewModel>(), Posts = new NewsFeedViewModel() { Posts = new List <PostsViewModel>(), Id = grpId.ToString() }, User = new UserViewModel() { ProfilePicture = userService.GetProfilePicture(User.Identity.GetUserId()).PhotoPath }, FriendsOfUser = new List <UserViewModel>() }; // Getting all members of this group var memberList = groupService.GetMembersOfGroup(grpId); foreach (var userId in memberList) { var currMember = userService.GetUserById(userId); myGroup.Members.Add(new UserViewModel() { Name = currMember.Name, UserId = currMember.Id, UserName = currMember.UserName, Birthday = currMember.Birthday, ProfilePicture = userService.GetProfilePicture(userId).PhotoPath }); } // Getting posts for the group var postService = new PostService(DbContext); var likedislikeService = new LikeDislikeService(DbContext); var postsOfGroup = groupService.GetAllPostsOfGroup(grpId); foreach (var userId in postsOfGroup) { // Assign a smiley according to if this user has liked or dislike or not done either var post = postService.GetPostById(userId); string lPic = null, dPic = null; if (likedislikeService.GetLikeDislike(User.Identity.GetUserId(), userId) == null) { lPic = "~/Content/images/smileySMALL.png"; dPic = "~/Content/images/sadfaceSMALL.png"; } else if (likedislikeService.GetLikeDislike(User.Identity.GetUserId(), userId).Like) { lPic = "~/Content/images/smileyGREEN.png"; dPic = "~/Content/images/sadfaceSMALL.png"; } else if (likedislikeService.GetLikeDislike(User.Identity.GetUserId(), userId).Dislike) { lPic = "~/Content/images/smileySMALL.png"; dPic = "~/Content/images/sadfaceRED.png"; } myGroup.Posts.Posts.Add(new PostsViewModel() { PostId = post.PostId, Body = post.Text, User = new UserViewModel() { Name = post.User.Name, UserId = post.User.Id, UserName = post.User.UserName, Birthday = post.User.Birthday, ProfilePicture = userService.GetProfilePicture(post.UserId).PhotoPath }, DateInserted = post.Date, LikeDislikeComment = new LikeDislikeCommentViewModel() { Likes = postService.GetPostsLikes(post.PostId), Dislikes = postService.GetPostsDislikes(post.PostId), Comments = postService.GetPostsCommentsCount(post.PostId) }, GroupId = post.GroupId, LikePic = lPic, DislikePic = dPic }); } // Getting all friends of the user so he can possibly add them to the group var userFriendList = userService.GetFriendsFromUser(User.Identity.GetUserId()); foreach (var userId in userFriendList) { if (!groupService.IsMemberOfGroup(grpId, userId)) { var friend = userService.GetUserById(userId); myGroup.FriendsOfUser.Add(new UserViewModel() { Name = friend.Name, UserId = friend.Id, UserName = friend.UserName, Birthday = friend.Birthday, ProfilePicture = userService.GetProfilePicture(userId).PhotoPath }); } } return(View("GroupDetails", myGroup)); }
public ActionResult AddPost(FormCollection collection) { string amount = collection["amount"]; string status = collection["status"]; string groupId = collection["idOfGroup"]; if (status.IsNullOrWhiteSpace() || amount.IsNullOrWhiteSpace()) { return(View("Error")); } // Create the new post and add it into the database DateTime now = DateTime.Now; var newPost = new Post { UserId = User.Identity.GetUserId(), Date = now, Text = status }; if (!groupId.IsNullOrWhiteSpace()) { newPost.GroupId = Int32.Parse(groupId); } DbContext.Posts.Add(newPost); DbContext.SaveChanges(); // Find out if this post belongs to the newsfeed or a group var groupService = new GroupService(DbContext); var userService = new UserService(DbContext); var list = new List <int>(); if (groupId.IsNullOrWhiteSpace()) { list = userService.GetEveryNewsFeedPostsForUser(User.Identity.GetUserId()); } else { list = groupService.GetAllPostsOfGroup(Int32.Parse(groupId)); } var postService = new PostService(DbContext); var likeDislikeService = new LikeDislikeService(DbContext); var postList = new List <PostsViewModel>(); int nOfCurrentStatuses = Int32.Parse(amount); // Get all statuses that are not currently displayed and display them for (int i = (list.Count - nOfCurrentStatuses) - 1; i >= 0; i--) { var post = postService.GetPostById(list[i]); // Assign a smiley according to if this user has liked or dislike or not done either var likeDislike = likeDislikeService.GetLikeDislike(post.UserId, post.PostId); string lPic = null, dPic = null; if (likeDislike == null) { lPic = "/Content/images/smileySMALL.png"; dPic = "/Content/images/sadfaceSMALL.png"; } else if (likeDislike.Like) { lPic = "/Content/images/smileyGREEN.png"; dPic = "/Content/images/sadfaceSMALL.png"; } else if (likeDislike.Dislike) { lPic = "/Content/images/smileySMALL.png"; dPic = "/Content/images/sadfaceRED.png"; } // Fill in the viewmodel postList.Add( new PostsViewModel() { PostId = post.PostId, Body = post.Text, User = new UserViewModel() { UserId = post.UserId, Name = userService.GetUserById(post.UserId).Name, ProfilePicture = userService.GetProfilePicture(post.UserId).PhotoPath }, DateInserted = post.Date, LikeDislikeComment = new LikeDislikeCommentViewModel() { Likes = postService.GetPostsLikes(post.PostId), Dislikes = postService.GetPostsDislikes(post.PostId), Comments = postService.GetPostsComments(post.PostId).Count }, LikePic = lPic, DislikePic = dPic, isUserPostOwner = (post.UserId == User.Identity.GetUserId()) }); } return(Json(postList, JsonRequestBehavior.AllowGet)); }
public ActionResult Comment(int?postId) { if (!postId.HasValue) { return(RedirectToAction("NewsFeed", "Home")); } // Assign a smiley according to if this user has liked or dislike or not done either var likedislikeService = new LikeDislikeService(DbContext); int pid = postId.Value; string lPic = null, dPic = null; if (likedislikeService.GetLikeDislike(User.Identity.GetUserId(), pid) == null) { lPic = "~/Content/images/smileySMALL.png"; dPic = "~/Content/images/sadfaceSMALL.png"; } else if (likedislikeService.GetLikeDislike(User.Identity.GetUserId(), pid).Like) { lPic = "~/Content/images/smileyGREEN.png"; dPic = "~/Content/images/sadfaceSMALL.png"; } else if (likedislikeService.GetLikeDislike(User.Identity.GetUserId(), pid).Dislike) { lPic = "~/Content/images/smileySMALL.png"; dPic = "~/Content/images/sadfaceRED.png"; } // Fill in the viewmodel var userService = new UserService(DbContext); var postService = new PostService(DbContext); var model = new CommentHelperViewModel { User = new UserViewModel() { UserId = postService.GetPostById(pid).UserId, Name = userService.GetUserById(postService.GetPostById(pid).UserId).Name, ProfilePicture = userService.GetProfilePicture(User.Identity.GetUserId()).PhotoPath }, Comments = new List <CommentViewModel>(), Post = new PostsViewModel() { PostId = pid, Body = postService.GetPostById(pid).Text, DateInserted = postService.GetPostById(pid).Date, LikeDislikeComment = new LikeDislikeCommentViewModel() { Likes = postService.GetPostsLikes(pid), Dislikes = postService.GetPostsDislikes(pid), Comments = postService.GetPostsCommentsCount(pid) }, User = new UserViewModel() { UserId = postService.GetPostById(pid).UserId, Name = userService.GetUserById(postService.GetPostById(pid).UserId).Name, ProfilePicture = userService.GetProfilePicture(postService.GetPostById(pid).UserId).PhotoPath }, LikePic = lPic, DislikePic = dPic } }; var commentService = new CommentService(DbContext); var commentIdList = postService.GetPostsComments(pid); foreach (var id in commentIdList) { var commentList = commentService.GetCommentById(id); model.Comments.Add( new CommentViewModel() { CommentId = commentList.CommentId, PostId = commentList.PostId, Body = commentList.Text, DateInserted = commentList.Date, User = new UserViewModel() { UserId = commentList.UserId, Name = userService.GetUserById(commentList.UserId).Name, UserName = userService.GetUserById(commentList.UserId).UserName, ProfilePicture = userService.GetProfilePicture(commentList.UserId).PhotoPath } }); } return(View(model)); }
public ActionResult NewsFeed() { // Fill in the newsfeed viewmodel to display on the newsfeed var userService = new UserService(DbContext); var newsFeed = new NewsFeedViewModel { Id = "-1", Posts = new List <PostsViewModel>(), User = new UserViewModel() { ProfilePicture = userService.GetProfilePicture(User.Identity.GetUserId()).PhotoPath } }; var postService = new PostService(DbContext); var likedislikeService = new LikeDislikeService(DbContext); var postList = userService.GetEveryNewsFeedPostsForUser(User.Identity.GetUserId()); foreach (var id in postList) { var post = postService.GetPostById(id); // Assign a smiley according to if this user has liked or dislike or not done either string lPic = null, dPic = null; if (likedislikeService.GetLikeDislike(User.Identity.GetUserId(), id) == null) { lPic = "~/Content/images/smileySMALL.png"; dPic = "~/Content/images/sadfaceSMALL.png"; } else if (likedislikeService.GetLikeDislike(User.Identity.GetUserId(), id).Like) { lPic = "~/Content/images/smileyGREEN.png"; dPic = "~/Content/images/sadfaceSMALL.png"; } else if (likedislikeService.GetLikeDislike(User.Identity.GetUserId(), id).Dislike) { lPic = "~/Content/images/smileySMALL.png"; dPic = "~/Content/images/sadfaceRED.png"; } newsFeed.Posts.Add( new PostsViewModel() { PostId = id, Body = post.Text, DateInserted = post.Date, LikeDislikeComment = new LikeDislikeCommentViewModel() { Likes = postService.GetPostsLikes(post.PostId), Dislikes = postService.GetPostsDislikes(post.PostId), Comments = postService.GetPostsCommentsCount(post.PostId) }, User = new UserViewModel() { UserId = post.UserId, Name = userService.GetUserById(post.UserId).Name, ProfilePicture = userService.GetProfilePicture(post.UserId).PhotoPath }, LikePic = lPic, DislikePic = dPic }); } return(View(newsFeed)); }
public ActionResult Profile(string id) { if (id.IsNullOrWhiteSpace()) { return(View("Error")); } var userService = new UserService(DbContext); var photoService = new PhotoService(DbContext); // Get the user cover photo, if he has none then display whitebackground.jpg var coverPhotoId = userService.GetCoverPhoto(id); var coverPhoto = photoService.GetPhotoById(coverPhotoId); string coverPhotoPath = coverPhoto == null ? "~/Content/images/whitebackground.jpg" : coverPhoto.PhotoPath; // Get if the current user and the profile user are best friends or family var friendShip = userService.GetFriendShip(User.Identity.GetUserId(), id); string bfStarPick = "~/Content/images/emptystar.png", fStarPick = "~/Content/images/emptystar.png"; if (friendShip != null) { if (friendShip.UserId == User.Identity.GetUserId()) { // if considered as best friend, then disbestfriend, else consider as best friend bfStarPick = friendShip.UserConsidersFriendAsBestFriend ? "~/Content/images/fullstar.png" : "~/Content/images/emptystar.png"; fStarPick = friendShip.UserConsidersFriendAsFamily ? "~/Content/images/fullstar.png" : "~/Content/images/emptystar.png"; } else if (friendShip.FriendUserId == User.Identity.GetUserId()) { // if considered as best friend, then disbestfriend, else consider as best friend bfStarPick = friendShip.FriendConsidersUsersAsBestFriend ? "~/Content/images/fullstar.png" : "~/Content/images/emptystar.png"; fStarPick = friendShip.FriendConsidersUsersAsFamily ? "~/Content/images/fullstar.png" : "~/Content/images/emptystar.png"; } else { return(View("Error")); } } var postService = new PostService(DbContext); var likedislikeService = new LikeDislikeService(DbContext); // Fill in the postviewmodel with all the profile user posts var postsViewModels = new List <PostsViewModel>(); var user = userService.GetUserById(id); var posts = userService.GetAllPostsFromUser(id); foreach (var postId in posts) { // Assign a smiley according to if this user has liked or dislike or not done either string lPic = null, dPic = null; if (likedislikeService.GetLikeDislike(User.Identity.GetUserId(), postId) == null) { lPic = "~/Content/images/smileySMALL.png"; dPic = "~/Content/images/sadfaceSMALL.png"; } else if (likedislikeService.GetLikeDislike(User.Identity.GetUserId(), postId).Like) { lPic = "~/Content/images/smileyGREEN.png"; dPic = "~/Content/images/sadfaceSMALL.png"; } else if (likedislikeService.GetLikeDislike(User.Identity.GetUserId(), postId).Dislike) { lPic = "~/Content/images/smileySMALL.png"; dPic = "~/Content/images/sadfaceRED.png"; } var post = postService.GetPostById(postId); postsViewModels.Add( new PostsViewModel() { PostId = postId, Body = post.Text, DateInserted = post.Date, LikeDislikeComment = new LikeDislikeCommentViewModel() { Likes = postService.GetPostsLikes(postId), Dislikes = postService.GetPostsDislikes(postId), Comments = postService.GetPostsCommentsCount(postId) }, User = new UserViewModel() { UserId = user.Id, UserName = user.UserName, Name = user.Name, ProfilePicture = userService.GetProfilePicture(post.UserId).PhotoPath, CoverPhoto = coverPhotoPath, Gender = user.Gender, Birthday = user.Birthday, Work = user.Work, School = user.School, Address = user.Address, BfStar = bfStarPick, FStar = fStarPick }, LikePic = lPic, DislikePic = dPic }); } // Fill in the profileviewmodel with the statuses and information of the profile user var model = new ProfileViewModel() { NewsFeed = new NewsFeedViewModel() { Posts = postsViewModels, Id = id }, User = new UserViewModel() { UserId = user.Id, UserName = user.UserName, Name = user.Name, ProfilePicture = userService.GetProfilePicture(id).PhotoPath, CoverPhoto = coverPhotoPath, Gender = user.Gender, Birthday = user.Birthday, Work = user.Work, School = user.School, Address = user.Address, BfStar = bfStarPick, FStar = fStarPick } }; return(View(model)); }
public void Initialize() { var mockDb = new MockDatabase(); #region LikesDislikes var ld1 = new LikeDislike() { PostId = 1, UserId = "1", Like = true, Dislike = false }; mockDb.LikesDislikes.Add(ld1); var ld2 = new LikeDislike() { PostId = 1, UserId = "2", Like = false, Dislike = true }; mockDb.LikesDislikes.Add(ld2); var ld3 = new LikeDislike() { PostId = 2, UserId = "1", Like = true, Dislike = false }; mockDb.LikesDislikes.Add(ld3); var ld4 = new LikeDislike() { PostId = 3, UserId = "2", Like = false, Dislike = true }; mockDb.LikesDislikes.Add(ld4); var ld5 = new LikeDislike() { PostId = 3, UserId = "3", Like = true, Dislike = false }; mockDb.LikesDislikes.Add(ld5); var ld6 = new LikeDislike() { PostId = 4, UserId = "4", Like = true, Dislike = false }; mockDb.LikesDislikes.Add(ld6); var ld7 = new LikeDislike() { PostId = 4, UserId = "1", Like = true, Dislike = false }; mockDb.LikesDislikes.Add(ld7); var ld8 = new LikeDislike() { PostId = 4, UserId = "2", Like = false, Dislike = true }; mockDb.LikesDislikes.Add(ld8); #endregion service = new LikeDislikeService(mockDb); }