public async Task <IActionResult> Edit(int id, [Bind("LikeId,AdventurePostId,UserId")] LikesTable likesTable) { if (id != likesTable.LikeId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(likesTable); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LikesTableExists(likesTable.LikeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AdventurePostId"] = new SelectList(_context.AdventuresPost, "PostId", "PostId", likesTable.AdventurePostId); ViewData["UserId"] = new SelectList(_context.User, "Id", "Id", likesTable.UserId); return(View(likesTable)); }
// GET: LikesTables/Delete/5 public async Task <IActionResult> Delete(int id) { string userid = this.User.FindFirstValue(ClaimTypes.NameIdentifier); LikesTable like = _context.Likes.Where(l => l.UserId == userid && l.AdventurePostId == id).SingleOrDefault(); _context.Likes.Remove(like); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "AdventurePosts")); }
public JsonResult addLike(int post_id) { if (Session["UserID"] != null) { int id = (int)Session["UserID"]; DatabaseEntities db = new DatabaseEntities(); LikesTable a = (from x in db.LikesTables where x.like_userID == id && x.like_postID == post_id select x).FirstOrDefault(); if (a != null) { var json = new { success = "already liked" }; return(Json(json)); } else { try { LikesTable data = new LikesTable(); data.like_postID = post_id; data.like_time = System.DateTime.Now; data.like_userID = id; db.LikesTables.Add(data); db.SaveChanges(); } catch (Exception e) { var json = new { success = e }; return(Json(json)); } var json2 = new { success = "ok" }; return(Json(json2)); } } else { var json2 = new { success = "Session TimeOut" }; return(Json(json2)); } }
// GET: LikesTables/Create public async Task <IActionResult> Create(string userid, int id) { //string user = this.User.FindFirstValue(ClaimTypes.NameIdentifier); //ViewModel check = new ViewModel(); //check.Likes = _context.Likes.Where(l => l.UserId == user).ToList(); //check.Users = _context.Likes.Where(l => check.Likes.Any(u => u.AdventurePostId == id)).ToList(); LikesTable like = new LikesTable(); like.UserId = userid; like.AdventurePostId = id; _context.Add(like); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "AdventurePosts")); }
// GET: LikesTables/Create public async Task <IActionResult> Create(int id) { string userid = this.User.FindFirstValue(ClaimTypes.NameIdentifier); LikesTable like = new LikesTable(); like.UserId = userid; like.AdventurePostId = id; bool contains = _context.Likes.Any(l => l.UserId == userid && l.AdventurePostId == id); if (contains == false) { _context.Add(like); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "AdventurePosts")); } else { return(RedirectToAction("Index", "AdventurePosts")); } }