public void AddLike(ApplicationUser user) { var like = Likes.SingleOrDefault(l => l.UserId == user.Id); if (like != null) { throw new CourseReviewException("You have liked this review already"); } var newlike = Like.Create(user); Likes.Add(newlike); }
public void RemoveLike(ApplicationUser user) { // 1. check lecture var like = Likes.SingleOrDefault(l => l.UserId == user.Id); if (like == null) { throw new NotFoundException("like not found"); } // 2. remove like var likeList = Likes.ToList(); likeList.Remove(like); Likes = likeList; }
public void AddOrRemoveLike(Profile profile) { var existingLike = Likes.SingleOrDefault(x => x.Profile == profile); if (existingLike == null) { Likes.Add(new Like { Post = this, Profile = profile, }); } else { Likes.Remove(existingLike); } }
public bool IsLikedByMe(Profile profile) => (Likes.SingleOrDefault(p => p.Profile == profile) != null);