public JsonResult Like(int id, string value) { bool success = false; Like like = new Like(); Article article = new Article(); ArticleRepository articleRepository = new ArticleRepository(); LikeRepository likeRepository = new LikeRepository(); article = articleRepository.GetById(id); List <Like> likeList = new List <Like>(); string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString(); int start = type.LastIndexOf(".") + 1; int positions = type.Length - start; type = type.Substring(start, positions); if (value == "Like") { like.ArticleID = id; like.UserID = AuthenticationManager.LoggedUser.Id; like.UserType = type; likeRepository.Save(like); success = true; } if (value == "UnLike") { like = likeRepository.GetAll(filter: l => l.ArticleID == id && l.UserID == AuthenticationManager.LoggedUser.Id && l.UserType == type).FirstOrDefault(); likeRepository.Delete(like); success = true; } return(Json(success, JsonRequestBehavior.AllowGet)); }
public JsonResult Like(long id) { var result = ORRepository.Get(id); if (result == null) { return(Json(new { Success = false, Error = "Не удалось найти результат" })); } // Получить текущего юзера var curUser = GetCurrentUser(); var like = LikeRepository.IsFavoriteResult(curUser.Id, id); if (like != null) { LikeRepository.Delete(like); return(Json(new { Success = true, Name = "like" })); } // Создать лайк like = LikeRepository.Create(); // Заполнить свойства like.UserId = curUser.Id; like.ResultId = result.Id; // Сохранить LikeRepository.Update(like); // Вернуться к списку операций return(Json(new { Success = true, Name = "dislike" })); }
public IHttpActionResult DeleteLike(int id, int uid) { Like like = likeRepo.GetAll().Where <Like>(x => x.postId == id && x.userId == uid).FirstOrDefault(); if (like == null) { return(StatusCode(HttpStatusCode.NoContent)); } likeRepo.Delete(like.likeId); return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Unlike(int postid, string userid) { int likeid = repository.GetLikeId(postid, userid); if (likeid != 0) { repository.Delete(likeid); repository.SaveChanges(); return(RedirectToAction("List", "NewsFeed")); } return(HttpNotFound()); }
public void DeletePost(int id) { List <Like> likes = likeRepo.GetAll().Where <Like>(x => x.postId == id).ToList(); List <Comment> comments = comRepo.GetAll().Where <Comment>(x => x.PostId == id).ToList(); foreach (var item in comments) { comRepo.Delete(item.CommentId); } foreach (var item in likes) { likeRepo.Delete(item.likeId); } this.Delete(id); }
public JsonResult Like(long id) { var result = ORRepository.Get(id); if (result == null) { return(Json(new { Success = false, Error = "Не удалось найти результат" })); } var curUser = GetCurrentUser(); //var like = LikeRepository.GetLikes(curUser.Id) // .FirstOrDefault(it => it.UserId == curUser.Id && it.ResultId == id); var like = LikeRepository.GetAll().FirstOrDefault(it => it.User.Id == curUser.Id && it.Result.Id == id); if (like != null) { //Dislike LikeRepository.Delete(like); return(Json(new { Success = true, Name = "Like" })); } // Создать лайк like = LikeRepository.Create(); // Заполнить свойства like.User = curUser; like.Result = result; // Сохранить LikeRepository.Update(like); // Вернуться к списку операций return(Json(new { Success = true, Name = "Dislike" })); }
public void DeleteLike(int id) { likeRepository.Delete(id); }
public JsonResult Like(int id, string value) { bool success = false; Like like = new Like(); Article article = new Article(); ArticleRepository articleRepository = new ArticleRepository(); LikeRepository likeRepository = new LikeRepository(); article = articleRepository.GetById(id); List<Like> likeList = new List<Like>(); string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString(); int start = type.LastIndexOf(".") + 1; int positions = type.Length - start; type = type.Substring(start, positions); if (value == "Like") { like.ArticleID = id; like.UserID = AuthenticationManager.LoggedUser.Id; like.UserType = type; likeRepository.Save(like); success = true; } if (value == "UnLike") { like = likeRepository.GetAll(filter: l => l.ArticleID == id && l.UserID == AuthenticationManager.LoggedUser.Id && l.UserType == type).FirstOrDefault(); likeRepository.Delete(like); success = true; } return Json(success, JsonRequestBehavior.AllowGet); }