public IActionResult DeleteListItem(string Slug, string listName, int Id) { var user = _userManager.Users.FirstOrDefault(u => u.Slug == Slug); var listItem = _context.ListItems.Include(l => l.List).Include(f => f.FilmItem).FirstOrDefault(li => li.Id == Id); if (listItem != null && user.Id == _userManager.GetUserId(User)) { FilmItemMethods.RemoveListItem(_context, listItem); TempData["message"] = $"Removed {listItem.FilmItem.Name} from '{listItem.List.Name}'"; } return(RedirectToAction("Details", "List", new { listName = listName })); }
public IActionResult ListsModal(string Slug, int SeasonNumber, int EpisodeNumber, bool check = false) { var listsChecked = Request.Form["Lists"].ToList(); var episode = _context.Episodes.Where(s => s.Slug == Slug).Where(s => s.Episode_SeasonNumber == SeasonNumber).Where(s => s.Episode_EpisodeNumber == EpisodeNumber).FirstOrDefault(); var lists = _context.Lists.Include(li => li.ListItems).Where(u => u.ApplicationUserId == _userManager.GetUserId(User)).ToList(); foreach (var list in lists) { var itemInList = list.ListItems.Where(m => m.FilmItem == episode).FirstOrDefault(); if (itemInList != null && !listsChecked.Contains(list.Id.ToString())) //unchecked -> checked { FilmItemMethods.RemoveListItem(_context, itemInList); } else if (itemInList == null && listsChecked.Contains(list.Id.ToString())) //checked -> unchecked { FilmItemMethods.SaveListItem(_context, list, episode); } } return(RedirectToAction("Details", new { Slug = Slug })); }