public async Task <IActionResult> LikeUser(long id, long recepientId) { if (!CheckUserId(id)) { return(Unauthorized()); } var like = await _likeRepo.GetLike(id, recepientId); if (like != null) { return(BadRequest("You already like this user")); } if (!await _userRepo.Existed(id) || !await _userRepo.Existed(recepientId)) { return(NotFound()); } var newLike = new Like { LikerId = id, LikeeId = recepientId }; _likeRepo.Add(newLike); if (await _likeRepo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to like user")); }
public ActionResult Like(long id) { bool success = false; try { long currentProfileId = 0; var objLike = new Like(); LikeModel objLikeModel = new LikeModel(); if (_repoUserProfile != null) { if (CurrentUser != null) { currentProfileId = _repoUserProfile.GetSingle(x => x.UserId == CurrentUser.UserId).Id; } } objLike = _repoLike.GetSingle(x => x.ProfileId == currentProfileId && x.EntityName == "comment" && x.EntityId == id); if (objLike == null) { objLikeModel.EntityName = "comment"; objLikeModel.EntityId = id; objLikeModel.ProfileId = currentProfileId; objLike = LikeMap.Map(objLikeModel); _repoLike.Add(objLike); _repoLike.Save(); } success = true; } catch (Exception e) { Elmah.ErrorSignal.FromCurrentContext().Raise(e); success = false; } return(Json(new { success = success })); }
public async Task <IActionResult> LikeUser(int likerId, int likeeId) { if (likerId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var doesLike = await _likeRepository.DoesLike(likerId, likeeId); if (doesLike != null) { return(BadRequest("Already liked!")); } if (await _repo.Get(likeeId) == null) { return(NotFound()); } var like = new Like { LikerId = likerId, LikeeId = likeeId }; _likeRepository.Add(like); if (await _likeRepository.SaveAll()) { return(Ok()); } return(BadRequest("Failed to like!")); }
public async Task <IActionResult> AddLike(int commentId, string userId) { var comment = await commentRepository.GetComment(commentId); var user = await appUserRepository.GetUser(userId); if (comment == null || user == null) { return(NotFound()); } var like = await likeRepository.GetLike(commentId, userId); if (like != null) { return(StatusCode(409, "This User already likes this comment.")); } var newLike = new Like { CommentId = commentId, AppUserId = userId }; likeRepository.Add(newLike); await unitOfWork.CompleteAsync(); return(Ok(comment.Id)); }
public Like Post([FromBody] Guid alvoId) { var like = new Like() { DesenvolvedorId = Guid.Parse(Request.Headers["desenvolvedorId"]), AlvoId = alvoId }; _likeRepository.Add(like); return(like); }
public ActionResult ToggleLike(string id) { var userId = HttpContext.User.Identity.Name; var story = storyRepository.GetSingle(s => s.Id == id, s => s.Likes); if (userId == story.OwnerId) { return(BadRequest("You can't like your own story")); } var user = userRepository.GetSingle(s => s.Id == userId); var existingLike = story.Likes.Find(l => l.UserId == userId); var payload = new LikeRelatedPayload { Username = user.Username, StoryTitle = story.Title }; if (existingLike == null) { hubContext.Clients.User(story.OwnerId).SendAsync( "notification", new Notification <LikeRelatedPayload> { NotificationType = NotificationType.LIKE, Payload = payload } ); likeRepository.Add(new Like { UserId = userId, StoryId = id }); } else { hubContext.Clients.User(story.OwnerId).SendAsync( "notification", new Notification <LikeRelatedPayload> { NotificationType = NotificationType.UNLIKE, Payload = payload } ); likeRepository.Delete(existingLike); } likeRepository.Commit(); return(NoContent()); }
public Like Add(Like like) { switch (like.ObjectType) { case "post": IncreaseCPFor100LikesAsync(like.ObjectId); _postRepository.IncreaseLikeCount(like.ObjectId); break; case "comment": _commentRepository.IncreaseLikeCount(like.ObjectId); break; } return(_likeRepository.Add(like)); }
public void Like(Like like) { Like likeFind = _likeRepository.FindLike(like.IdBaiViet, like.IdNguoiDung); if (likeFind != null) { UnLike(likeFind); } else { BaiViet baiViet = _baiVietRepository.GetSingleById((int)like.IdBaiViet); baiViet.SoLike++; _unitOfWork.Commit(); like.TinhTrang = true; _likeRepository.Add(like); } }
public Like LikeOrDislike(int EntryID, int PersonID) { var controlLike = _likeRepository.GetAll().Where(x => x.PersonID == PersonID && x.EntryID == EntryID).FirstOrDefault(); if (controlLike != null) { _likeRepository.Remove(controlLike.LikeID); return(null); } else { Like like = new Like { LikeDate = DateTime.Now.Date, EntryID = EntryID, PersonID = PersonID }; return(_likeRepository.Add(like)); } }
public async Task <ObjectResult <LikeResponse> > Like(int quizId, int userId) { var quiz = await _quizRepository.GetQuiz(quizId); if (quiz == null) { return(new ObjectResult <LikeResponse> { Errors = new[] { "Quiz with given id was not found" } }); } Like like; if ((like = await _likeRepository.GetLike(quizId, userId)) != null) { return(new ObjectResult <LikeResponse> { Found = true, Success = true, Object = _mapper.Map <LikeResponse>(like) }); } var likeModel = new LikeResponse { QuizId = quizId, UserId = userId }; like = _mapper.Map <Like>(likeModel); _likeRepository.Add(like); if (await _likeRepository.SaveChangesAsync()) { return(new ObjectResult <LikeResponse> { Found = true, Success = true, Object = likeModel }); } return(new ObjectResult <LikeResponse> { Found = true, Errors = new[] { "No rows were affected" } }); }
public void Add(Like like) { likeRepository.Add(like); }
public async Task AddAndSafe(Like like) { _likeRepository.Add(like); await _likeRepository.Save(); }
public ResultMessage <Like> Add(Like data) { return(likeRepository.Add(data)); }