public ActionResult SetLikeState(int noteid, bool liked) { int res = 0; Liked like = likedManager.Find(x => x.Note.Id == noteid && x.LikedUser.Id == CurrentSession.User.Id); Note note = noteManager.Find(x => x.Id == noteid); if (like != null && liked == false) { res = likedManager.Delete(like); } else if (like == null && liked == true) { res = likedManager.Insert(new Liked() { LikedUser = CurrentSession.User, Note = note }); } if (res > 0) { if (liked == true) { note.LikeCount++; } else { note.LikeCount--; } noteManager.Update(note); return(Json(new { hasError = true, errorMessage = string.Empty, result = note.LikeCount })); }//hasError ters mantık ile yaptım çünkü auth ile kullanıcı kontrolü yapıldığında action calısmıyor ve scriptte hasError kontrolünde hasError default olarak false geldiği için patlıyor. return(Json(new { hasError = false, errorMessage = "Beğenme işlemi gerçekleştirilemedi.", result = note.LikeCount })); }
public ActionResult SetLikeState(int noteid, bool liked) { int res = 0; Liked like = likedManager.Find(x => x.Note.Id == noteid && x.LikedUser.Id == CurrentSession.User.Id); Note note = noteManager.Find(x => x.Id == noteid); if (like != null && liked == false) { res = likedManager.Delete(like); } else if (like == null && liked == true) { res = likedManager.Insert(new Liked() { LikedUser = CurrentSession.User, Note = note }); } if (res > 0) { if (liked) { note.LikeCount++; } else { note.LikeCount--; } res = noteManager.Update(note); return(Json(new { hasError = false, errorMessage = string.Empty, result = note.LikeCount })); } return(Json(new { hasError = true, errorMessage = "Begenme işlemi gerçekleştirilemedi.", result = note.LikeCount })); }
public ActionResult SetLikeState(int shareid, bool liked) { int res = 0; Liked like = likedManager.Find(x => x.Share.ShareId == shareid && x.LikedUser.Id == CurrentSession.manager.Id); Share share = shareManager.Find(x => x.ShareId == shareid); if (like != null && liked == false) { res = likedManager.Delete(like); } else if (like == null && liked == true) { res = likedManager.Insert(new Liked() { LikedUser = CurrentSession.manager, Share = share }); } if (res > 0) { if (liked) { share.LikeCount++; } else { share.LikeCount--; } shareManager.Update(share); return(Json(new { hasError = false, errorMessage = string.Empty, result = share.LikeCount })); } return(Json(new { hasError = true, errorMessage = "Beğenme işlemi gerçekleştirilemedi", result = share.LikeCount })); }
public ActionResult SetLikeState(int noteid, bool liked) { if (CurrentSession.User == null) { return(null); } //tru ve false olmadıgını anlamak icin int res = 0; //böyle bir like varmı.Kullanıcı like yapmışsa kayıt gelir Liked like = likedManager.Find(x => x.Note.Id == noteid && x.LikedUser.Id == CurrentSession.User.Id); //notu al Note note = noteManager.Find(x => x.Id == noteid); //begenilmişse false gelirse unlike yapılabilir if (like != null && liked == false) { //unlike yap res = likedManager.Delete(like); } //kulanıcı like yapıyo else if (like == null && liked == true) { res = likedManager.Insert(new Liked() { //begenen kişi suanki kullanıcı LikedUser = CurrentSession.User, Note = note }); } //bir işlem yapıldıysa if (res > 0) { //like yapıldıysa bir arttır if (liked) { note.LikeCount++; } //else ise unlike yapılmısştır else { note.LikeCount--; } //notu update et res = noteManager.Update(note); return(Json(new { hasError = false, errorMessage = string.Empty, result = note.LikeCount })); } return(Json(new { hasError = true, errorMessage = "zaten begendiniz.", result = note.LikeCount })); }
public ActionResult SendLiked(int?nID, bool state) { Note note = null; EvernoteUser user = null; int?lID = CSession.User.ID; note = noteManager.Find(x => x.ID == nID); user = userManager.Find(x => x.ID == lID); int count = 0; if (nID != null && lID != null) { if (note != null && user != null) { if (state) { Liked Liked = likedManager.Find(x => x.LikedUser.ID == lID && x.Note.ID == note.ID); count = likedManager.Delete(Liked); if (count > 0) { note.likeCount = note.likeCount - 1; noteManager.Update(note); return(Json(new { status = true, likedCount = note.likeCount })); } } else { Liked liked = new Liked(); liked.LikedUser = user; liked.Note = note; count = likedManager.insert(liked); if (count > 0) { note.likeCount = note.likeCount + 1; noteManager.Update(note); return(Json(new { status = true, likedCount = note.likeCount })); } } return(Json(new { status = false, text = "Beğendiğiniz Not Silinmiş Olabilir!" })); } return(Json(new { status = false, text = "Beğendiğiniz Not Silinmiş Olabilir!" })); } return(Json(new { status = false, text = "Beğendiğiniz Not Silinmiş Olabilir!" })); }
public ActionResult SetLikeState(int noteid, bool liked) { int res = 0; if (CurrentSession.User == null) { return(Json(new { hasError = true, errorMessage = "Beğenme işlemi için giriş yapmalısınız.", result = 0 })); } //Like var mı o kullanıcıya ait? Liked like = likedManager.Find(x => x.Note.Id == noteid && x.LikedUser.Id == CurrentSession.User.Id); Note note = noteManager.Find(x => x.Id == noteid); //like dolu gelmiş ise bidaha like yapılmaması if (like != null && liked == false) { res = likedManager.Delete(like); } else if (like == null && liked == true) //like yapmadığını like yapmamaya çalışamaz { res = likedManager.Insert(new Liked() { LikedUser = CurrentSession.User, Note = note }); } if (res > 0) { if (liked) { note.LikeCount++; //like yapma } else { note.LikeCount--; //like yapmama } res = noteManager.Update(note); return(Json(new { hasError = false, errorMessage = string.Empty, result = note.LikeCount })); } return(Json(new { hasError = true, errorMessage = "Beğenme işlemi gerçekleştirilemedi.", result = note.LikeCount })); }
public ActionResult SetLikeState(int noteid, bool liked) { int res = 0; if (SessionManager.User == null) { return(Json(new { hasError = true, errorMessage = "Giriş yapmış kullanıcılar not beğenebilir!", result = 0 })); } UnLike like = likedManager.Find(x => x.Note.Id == noteid && x.LikedUser.Id == SessionManager.User.Id); UnNotes note = noteManager.Find(x => x.Id == noteid); if (like != null && liked == false) { res = likedManager.Delete(like); } else if (like == null && liked == true) { res = likedManager.Insert(new UnLike() { LikedUser = SessionManager.User, Note = note }); } if (res > 0) { if (liked) { note.LikeTotal++; } else { note.LikeTotal--; } res = noteManager.Update(note); return(Json(new { hasError = false, errorMessage = string.Empty, result = note.LikeTotal })); } return(Json(new { hasError = true, errorMessage = "Beğenme işlemi gerçekleştirilemedi.", result = note.LikeTotal })); }
public ActionResult SetLikeState(int productid, bool liked) { int res = 0; if (CurrentSession.User == null) { return(Json(new { hasError = true, errorMessage = "Beğenme işlemi için giriş yapmalısınız.", result = 0 })); } Liked like = likedManager.Find(x => x.Product.Id == productid && x.LikedUser.Id == CurrentSession.User.Id); Product product = productManager.Find(x => x.Id == productid); if (like != null && liked == false) { res = likedManager.Delete(like); } else if (like == null && liked == true) { res = likedManager.Insert(new Liked() { LikedUser = CurrentSession.User, Product = product }); } if (res > 0) { if (liked) { product.LikeCount++; } else { product.LikeCount--; } res = productManager.Update(product); return(Json(new { hasError = false, errorMessage = string.Empty, result = product.LikeCount })); } return(Json(new { hasError = true, errorMessage = "Beğenme işlemi gerçekleştirilemedi.", result = product.LikeCount })); }
public ActionResult SetLikeState(int noteid, bool liked) { using (LikedManager likedManager = new LikedManager()) { using (SharingManager sharingManager = new SharingManager()) { int result = 0; Liked like = likedManager.Find(x => x.Shareing.Id == noteid && x.likedUser.Id == CurrentSession.shareBookUser.Id && !x.likedUser.isDeleted && !x.Shareing.isDelete); Sharing share = sharingManager.Find(x => x.Id == noteid && !x.Owner.isDeleted && !x.isDelete && !x.Owner.isDeleted); if (like != null && liked == false) { result = likedManager.Delete(like); } else if (like == null && liked == true) { result = likedManager.Insert(new Liked() { likedUser = CurrentSession.shareBookUser, Shareing = share }); } if (result > 0) { if (liked) { share.LikeCount++; } else { share.LikeCount--; } sharingManager.Update(share); return(Json(new { hasError = false, errorMessage = string.Empty, result = share.Likes.Where(x => !x.likedUser.isDeleted).ToList().Count })); } return(Json(new { hasError = true, errorMessage = "Beğenme işlemi gerçekleştirilemedi", result = share.Likes.Where(x => !x.likedUser.isDeleted).ToList().Count })); } } }
public ActionResult SetLikeState(int noteid, bool liked) { if (CurrentSession.User != null) { int res = -1; Liked like = _likedManager.Find(x => x.LikedUser.Id == CurrentSession.User.Id && x.Note.Id == noteid); Note note = _noteManager.Find(x => x.Id == noteid); if (like != null && liked == false) { res = _likedManager.Delete(like); } else if (like == null && liked == true) { res = _likedManager.Insert(new Liked() { LikedUser = CurrentSession.User, Note = note }); } if (res > 0) { if (liked) { note.LikeCount++; } else { note.LikeCount--; } res = _noteManager.Update(note); return(Json(new { hasError = false, errorMessage = string.Empty, result = note.LikeCount })); } return(Json(new { hasError = true, errorMessage = "Beğenme işlemi gerçekleştirilemedi", result = note.LikeCount })); } else { return(HttpNotFound("Giriş yapılmadığı için hata aldınız!")); } }
public ActionResult SetLikeState(int articleid, bool liked) { if (CurrentSession.User != null) { int res = 0; Liked like = liked_mngr.Find(x => x.Articles.Id == articleid && x.LikedUser.Id == CurrentSession.User.Id); //Böyle bir Like var mı?Eğer kullanıcı Likelamış ise bize kayıt gelecek zaten! Article article = article_mngr.Find(x => x.Id == articleid); //Peki böyle bir article var mı? database de Admin silmis olabilir vs. if (like != null && liked == false) // like!=null demek bu article zaten likelanmış o zaman bize gelen liked==false olması lazım ki daha onceden likelanmış oldugunu anlayalım. { res = liked_mngr.Delete(like); } else if (like == null && liked == true) { res = liked_mngr.Insert(new Liked() { LikedUser = CurrentSession.User, Articles = article }); } if (res > 0) { if (liked) { article.LikeCount++; } else { article.LikeCount--; } res = article_mngr.Update(article); return(Json(new { hasError = false, errorMessage = string.Empty, result = article.LikeCount })); } return(Json(new { hasError = true, errorMessage = "liking process could not be performed.", result = article.LikeCount })); } return(Json(new { hasError = true, errorMessage = "Please register or login!", result = -1 })); }
public ActionResult GetLikeState(int noteId, bool likedState) { int result = 0; if (CurrentSession.User != null) { #region DB'de like-dislike işlemlerinin işlenmesi Liked liked = likedManager.Find(q => q.Note.Id == noteId && q.LikedUser.Id == CurrentSession.User.Id); Note note = noteManager.Find(q => q.Id == noteId); if ((note != null && liked != null) && likedState == false) { result = likedManager.Delete(liked); } else if ((note != null && liked == null) && likedState == true) { result = likedManager.Insert(new Liked { LikedUser = CurrentSession.User, Note = note, }); } #endregion #region LikeCount değerini ayarlama if (note != null && result > 0) { if (likedState) { note.LikeCount++; } else { note.LikeCount--; } result = noteManager.Update(note); return(Json(new { hasError = false, errorMessage = string.Empty, likeCount = note.LikeCount })); } #endregion } return(Json(new { hasError = true, errorMessage = "Beğenme işlemide hata oluştu!", likeCount = 0 })); }
public ActionResult SetLikeStatus(int noteId, bool liking) { Liked liked = likedManager.Find(x => x.Note.Id == noteId && x.LikedUser.Id == CurrentSession.User.Id); Note note = noteManager.Find(x => x.Id == noteId); int result = 0; if (liked != null && liking == false) { result = likedManager.Delete(liked); } else if (liked == null && liking == true) { result = likedManager.Insert(new Liked { LikedUser = CurrentSession.User, Note = note }); } if (result > 0) { if (liking == true) { note.LikeCount++; } else { note.LikeCount--; } if (noteManager.Update(note) > 0) { return(Json(new { errorMessage = String.Empty, hasError = false, result = note.LikeCount })); } } return(Json(new { errorMessage = "Beğenme işlemi başarısız!", hasError = true, result = note.LikeCount })); }
public ActionResult SetLikeState(int noteid, bool liked) { int res = 0; Liked like = lm.Find(x => x.Note.Id == noteid && x.LikedUser.Id == SessionHelper.User.Id); Note note = nm.Find(x => x.Id == noteid); if (like != null && liked == false) { res = lm.Delete(like); } else if (like == null && liked == true) { res = lm.Insert(new Liked() { LikedUser = SessionHelper.User, Note = note }); } if (res > 0) { if (liked) { note.LikeCount++; } else { note.LikeCount--; } res = nm.Update(note); return(Json(new { hasError = false, errorMessage = string.Empty, result = note.LikeCount })); } return(Json(new { hasError = true, errorMessage = "Beğenmede hata oluştu...", result = note.LikeCount })); }
public JsonResult SetLikeState(int id, int liked) { int res = 0; Liked like = likedManager.Find(x => x.Book.Id == id && x.LikedUser.Id == CurrentSession.User.Id);//like'lanmış mı diye kontrol edeceğiz Book book = bookManager.Find(x => x.Id == id); if (like != null && liked <= 0)//db'den like'lanmış olarak kayıt dönmeli ve önyüzden liked nesnesi false yani like'lanmamış olarak dönmeli yani false { res = likedManager.Delete(like); } else if (like == null && liked > 0) { res = likedManager.Insert(new Liked() { LikedUser = CurrentSession.User, Book = book, Point = liked }); } else if (like != null && liked > 0) { like.Book = book; like.LikedUser.Id = CurrentSession.User.Id; like.Point = liked; res = likedManager.Update(like); } if (res > 0)//bir işlem yaptıysam { if (liked > 0) { if (like != null && like.LikedUser.Id != CurrentSession.User.Id) { book.LikeCount++; } else if (like == null) { book.LikeCount++; } } else { book.LikeCount--; } res = bookManager.Update(book); var bookSumPoint = likedManager.List().Where(x => x.Book.Id == id).Sum(x => x.Point); var bookLikeCount = bookManager.List().Where(x => x.Id == id).Select(x => x.LikeCount).First(); var avgPoint = bookSumPoint / bookLikeCount; return(Json(new { hasError = false, errorMessage = string.Empty, result = avgPoint })); } return(Json(new { hasError = true, errorMessage = "Beğenme işlemi gerçekleştirilemedi.", result = book.LikeCount })); }