public ActionResult Like(int id) { string uid = User.Identity.GetUserId(); Profile profile = db1.Profiles.Where(x => x.USERID == uid).FirstOrDefault(); PostLike like = db2.PostLikes.Where(x => x.PostID == id && x.ProfileID == profile.ID).FirstOrDefault(); if (like == null) { PostLike newlike = new PostLike(); Post update = db.Posts.ToList().Find(x => x.ID == id); update.Likes += 1; newlike.PostID = id; newlike.Liked = true; newlike.ProfileID = profile.ID; db.SaveChanges(); db2.PostLikes.Add(newlike); db2.SaveChanges(); return(RedirectToAction("HomePage", "UserHomePage")); } else if (like.Liked == true) { return(RedirectToAction("HomePage", "UserHomePage")); } else { return(RedirectToAction("HomePage", "UserHomePage")); } }
public PostLikeController(PostLikeContext context) { _context = context; if (_context.PostLikes.Count() == 0) { _context.PostLikes.Add(new PostLike { ID = 69420 }); _context.SaveChanges(); } }
public IActionResult Create(PostLike newPostLike) { _context.PostLikes.Add(newPostLike); _context.SaveChanges(); return(CreatedAtRoute("GetPostLikes", new { id = newPostLike.ID }, newPostLike)); }