public string AjaxTest(ActorLike obj) { int actorId = obj.ActorId; LikeSet(actorId); return("Test"); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ActorId,UserId,Like")] ActorLike actorLike) { if (id != actorLike.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(actorLike); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ActorLikeExists(actorLike.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(actorLike)); }
public async Task <IActionResult> Create([Bind("Id,ActorId,UserId,Like")] ActorLike actorLike) { if (ModelState.IsValid) { _context.Add(actorLike); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(actorLike)); }
public ActionResult LikeSet(int actorId) { userId = (User.Identity.GetUserId()); var actor = _context.Actors.FirstOrDefault(x => x.Id == actorId); var searchingRecord = _context.ActorLike.FirstOrDefault(x => x.ActorId == actorId && x.UserId == userId); if (searchingRecord == null) { ActorLike actorLike = new ActorLike { ActorId = actorId, Actor = actor, UserId = userId, Like = true }; _context.ActorLike.Add(actorLike); int iii = actorLike.Id; _context.SaveChanges(); } else { searchingRecord.Like = !searchingRecord.Like; } _context.SaveChangesAsync(); return(View("Index")); }