public IActionResult Like(int id) { var post = _postService.GetPost(id); var user = _userService.GetUser(User.Identity.Name); if (_postService.CheckIfUserLikedPost(post, user)) { return(RedirectToAction("Post", "Home", new { id = id })); } var newLike = new Like(); newLike.User = user; newLike.Post = post; newLike = _likeService.AddWithCommit(newLike); _postService.AddLike(newLike.Post, newLike); var newNotification = new Notification { NotifiedUser = post.User, NotifyingUser = user, NotificationType = NotificationType.Like, Post = post }; _notificationService.AddNotification(newNotification); _ccDbContextService.Commit(); return(RedirectToAction("Post", "Home", new { id = id })); }
public async Task <LikeResult> LikePost([FromBody] Like like) { return(await _postService.AddLike(like)); }