public IActionResult LikePost([FromForm] Guid postId) { try { var currentUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (_postService.Like(postId) && !_likeService.BegendinMi(Guid.Parse(currentUserId), postId)) { _likeService.Add(new Like { Id = Guid.NewGuid(), PostId = postId, BegenenId = Guid.Parse(currentUserId) }); return(Ok("Başarılı")); } else { return(NotFound("Zaten beğenmişsiniz.")); } } catch (Exception e) { return(BadRequest(e)); } }
public async Task <IActionResult> LikePost(long id) { var userId = GetUserIdFromClaims(User); if (userId == null) { return(Unauthorized(new UnauthorizedErrorViewModel())); } var post = await _postService.GetByIdAsync(id); if (post == null) { return(NotFound(NotFoundErrorViewModel.Create(nameof(Post), id))); } var like = await _likeService.FindAsync(likeQuery => likeQuery.PostId == id && likeQuery.UserId == userId); if (like == null) { like = new Like { PostId = post.Id, UserId = userId.Value }; _likeService.Add(like); } else { _likeService.Remove(like); } await _context.SaveChangesAsync(); return(Ok()); }
public IHttpActionResult Like(int idp, int idu) { Like like = new Like() { ParentLike = idu, PublicationLike = idp }; likeService.Add(like); likeService.Commit(); MyService.Like(idp); Dislike dislike = null; var like1 = dislikeService.GetMany(); foreach (var l in like1) { if (l.ParentDislike == idu && l.PublicationDislike == idp) { dislike = l; } } if (dislike != null) { dislikeService.Delete(dislike); dislikeService.Commit(); MyService.annud(idp); } return(Ok()); }
public IActionResult Post([FromForm] int photoId) { var result = User.Claims.GetUserId(); if (!result.IsSuccessful && photoId > 0) { return(BadRequest()); } IDataResult <Like> dataResult = _likeService.Add(new Like() { UserId = result.Data, PhotoId = photoId }); var channelId = _photoService.GetById(photoId).Data.ChannelId; if (dataResult.IsSuccessful) { this.RemoveCacheByContains(result.Data + "/api/likes/islike/" + photoId); this.RemoveCacheByContains("photos/" + photoId); this.RemoveCacheByContains(channelId + "/channel-photos"); this.RemoveCacheByContains(result.Data + "/user-photos"); this.RemoveCacheByContains(result.Data + "/like-photos"); this.RemoveCacheByContains(result.Data + "/user-comment-photos"); return(Ok(dataResult.Data)); } return(BadRequest(dataResult.Message)); }
public IActionResult AddLike(int idReview) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } string currentUserId = GetCurrentUserId(); bool like = _likeService.CheckLike(currentUserId, idReview); try { if (like == true) { _likeService.Delete(currentUserId, idReview); } else { _likeService.Add(currentUserId, idReview); } } catch (ValidationException ex) { _loggerService.LogWarning(CONTROLLER_NAME + $"/addlike/{idReview}", LoggerConstants.TYPE_POST, $"add like review id: {idReview} error {ex.Message}", GetCurrentUserId()); return(RedirectToAction("Error", "Home", new { requestId = "400", errorInfo = ex.Message })); } _loggerService.LogInformation(CONTROLLER_NAME + $"/addlike/{idReview}", LoggerConstants.TYPE_POST, $"add like review id: {idReview} successful", GetCurrentUserId()); return(RedirectToAction("Index")); }
public async Task <IActionResult> LikeUser(int id, int recipientId) { if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var like = await _likeService.GetLike(id, recipientId); if (like != null) { return(BadRequest("You already like this user")); } if (await _datingService.GetUser(recipientId) == null) { return(NotFound()); } like = new Like { LikerId = id, LikeeId = recipientId }; try { _likeService.Add(like); return(Ok()); } catch { return(BadRequest("Failed to like user")); } }
public RedirectToRouteResult Like(int id, PublicationVM pubvm, HttpPostedFileBase file) { Like like = new Like() { ParentLike = (int)Session["idu"], PublicationLike = id }; likeService.Add(like); likeService.Commit(); Service.Like(id); Dislike dislike = null; var like1 = dislikeService.GetMany(); foreach (var l in like1) { if (l.ParentDislike == (int)Session["idu"] && l.PublicationDislike == id) { dislike = l; } } if (dislike != null) { dislikeService.Delete(dislike); dislikeService.Commit(); Service.annud(id); } return(RedirectToAction("Index")); }
public IActionResult Like([FromBody] Like param) { var identity = (ClaimsIdentity)User.Identity; var userId = identity.FindFirst("user_id").Value; param.UserId = userId; _likeService.Add(param); return(Ok(param)); }
public IActionResult Add([FromForm(Name = ("like"))] Like like) { var result = _likeService.Add(like); if (result.Succcess) { return(Ok(result)); } return(BadRequest(result)); }
public JsonResult LikePost(int postId) { bool stt = false; var likes = likeService.GetByPostId(postId); if (likes.Count() > 0) { var unlike = likes.Where(x => x.PostId == postId && x.CreatedBy == Convert.ToInt32(Session[UserSession.UserId])).FirstOrDefault(); if (unlike != null) { likeService.Delete(unlike); stt = false; } else { var like = new Like(); like.PostId = postId; like.CreatedBy = Convert.ToInt32(Session[UserSession.UserId]); likeService.Add(like); stt = true; } } else { // first like var like = new Like(); like.PostId = postId; like.CreatedBy = Convert.ToInt32(Session[UserSession.UserId]); likeService.Add(like); stt = true; } likes = likeService.GetByPostId(postId); foreach (var item in likes) { item.User = userService.GetById(Convert.ToInt32(item.CreatedBy)); } return(Json(new { data = likes, status = stt })); }
public ActionResult AddLike(LikeVM likevm, int idpa) { Interesse like = new Interesse(); like.IdAnnonce = idpa; like.UserID = User.Identity.GetUserId(); LikeService.Add(like); LikeService.Commit(); return(View()); }
public PartialViewResult AddLike(int idpa) { Like like = new Like() { idPub = idpa, idUser = "******" }; likeserv.Add(like); likeserv.Commit(); return(PartialView("DellLike", new LikeVM { idPub = idpa })); }
public JsonResult Increment(int id, int value) { int val = value; int Proc = 0; SessionUser session = userSessionService.Get("LoginUser"); Blog blog = blogService.Get(x => x.id == id && x.IsActive); if (EntityBase.IsNotNull(blog) && EntityBase.IsNotNull(session)) { Like like = likeService.Get(x => x.IsActive == true && x.Userid == session.id && x.Blogid == blog.id && x.IsLike == (value == 1)); if (EntityBase.IsNotNull(like)) { like.IsActive = false; likeService.Update(like); likeService.Save(); val *= -1; Proc = 0; } else { Proc = (value == 1 ? 1 : -1); like = likeService.Get(x => x.IsActive == true && x.Userid == session.id && x.Blogid == blog.id && x.IsLike == !(value == 1)); if (EntityBase.IsNotNull(like)) { like.IsActive = false; likeService.Update(like); likeService.Save(); val *= 2; } like = new Like() { Blogid = blog.id, Userid = session.id, IsLike = (value == 1) }; likeService.Add(like); likeService.Save(); } blogService.PointIncrementation(blog, val); } string color = Proc == 1 ? "#9494FF" : (Proc == -1 ? "#FF8b60" : "#6c757d"); return(Json(new { Point = blog.Points, Color = color })); }
public void Like(int authorId, int commentId) { var existingLikes = likeService.GetAll(commentId); LikeViewModel viewModel = new LikeViewModel(); viewModel.AuthorId = authorId; viewModel.CommentId = commentId; var existingLike = existingLikes.FirstOrDefault(x => x.AuthorId == authorId); if (existingLike == null) { likeService.Add(viewModel); var likes = likeService.GetAll(commentId); Clients.All.SendAsync("ReceiveLike", viewModel.CommentId, likes.Count()); } else { likeService.Delete(existingLike.Id); var likes = likeService.GetAll(commentId); Clients.All.SendAsync("ReceiveLike", viewModel.CommentId, likes.Count()); } }