public IActionResult LikeColor(UserLikesColor FromForm) { // If user id was coming from session and not the form // I would attach that here prior to adding it to the database _context.Add(FromForm); _context.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult DeleteLike(int UserId, int ColorId) { // Pull the association object from the database that indicates the // many to many relationship between a given user and a given color UserLikesColor ToRemove = _context.UsersLikeColors.FirstOrDefault(ulc => ulc.UserId == UserId && ulc.ColorId == ColorId); // Remove it from the database _context.Remove(ToRemove); // And save our changes _context.SaveChanges(); return(RedirectToAction("Index")); }