public ResponseLike AddWithCommit(ResponseLike newLike) { Likes.Add(newLike); _context.SaveChanges(); return(newLike); }
public IActionResult LikeResponse(int ResponseId, int PostId) { var response = _responseService.GetResponse(ResponseId); var user = _userService.GetUser(User.Identity.Name); if (_responseService.CheckIfUserLikedResponse(response, user)) { return(RedirectToAction("Post", "Home", new { id = PostId })); } var post = _postService.GetPost(PostId); var newLike = new ResponseLike(); newLike.Response = response; newLike.User = user; newLike = _responseLikeService.AddWithCommit(newLike); _responseService.AddLike(newLike.Response, newLike); var newNotification = new Notification { NotifiedUser = response.User, NotifyingUser = user, NotificationType = NotificationType.LikeResponse, Post = post }; _notificationService.AddNotification(newNotification); _ccDbContextService.Commit(); return(RedirectToAction("Post", "Home", new { id = PostId })); }
public void AddLike(Response response, ResponseLike newLike) { responses.FirstOrDefault(r => r.Id == response.Id) .Likes .Add(newLike); }
public void AddLikeToResponse(Post post, Response response, ResponseLike responseLike) { Posts.FirstOrDefault(p => p.Id == post.Id) .Responses.FirstOrDefault(r => r.Id == response.Id) .Likes.Add(responseLike); }