public static void Delete(GenreMovie item) { try { var items = GetAll(); var itemToDelete = items.Where(p => p.Id == item.Id).FirstOrDefault(); items.Remove(itemToDelete); Add(items); } catch { } }
public static void Add(GenreMovie item) { try { var items = GetAll(); if (items.Any(p => p.Id == item.Id || (p.GenreId == item.GenreId && p.MovieId == item.MovieId))) return; items.Add(item); Add(items); } catch { } }
public static void Update(GenreMovie item) { try { var items = GetAll(); var oldItem = items.Where(p => p.Id == item.Id).FirstOrDefault(); items.Remove(oldItem); items.Add(item); Add(items); } catch { } }
public ActionResult ManageGenres(IEnumerable<CheckboxViewModel> checkboxes, Guid movieId) { var selectedItems = checkboxes.Where(x => x.IsChecked); var format = string.Join(",", selectedItems.Select(x => x.Name)); GenreMovies.DeleteByMovieId(movieId); foreach (var item in selectedItems) { var movieGenre = new GenreMovie { Id = Guid.NewGuid(), MovieId = movieId, GenreId = item.Id, }; GenreMovies.Add(movieGenre); } return RedirectToAction("ManageGenres", new { @id = movieId }); }