public async Task <IActionResult> Edit(int id, [Bind("GenreMovieID,MovieID,GenreID")] GenreMovie genreMovie) { if (id != genreMovie.GenreMovieID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(genreMovie); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GenreMovieExists(genreMovie.GenreMovieID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["GenreID"] = new SelectList(_context.genres, "GenreID", "GenreName", genreMovie.GenreID); ViewData["MovieID"] = new SelectList(_context.movies, "MovieID", "Title", genreMovie.MovieID); return(View(genreMovie)); }
public void Delete(GenreMovie delGenreMovie) { if (delGenreMovie != null) { db.GenreMovie.Remove(delGenreMovie); db.SaveChanges(); } }
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 ActionResult New(GenreMovie requestGenreMovie) { GenreMovie gm = new GenreMovie(); gm.MovieId = requestGenreMovie.MovieId; gm.GenreId = requestGenreMovie.GenreId; dgm.GenreMovies.Add(gm); dgm.SaveChanges(); return(RedirectToAction("Edit", "Movie", new { id = requestGenreMovie.MovieId })); }
public async Task <IActionResult> Create([Bind("GenreMovieID,MovieID,GenreID")] GenreMovie genreMovie) { if (ModelState.IsValid) { _context.Add(genreMovie); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["GenreID"] = new SelectList(_context.genres, "GenreID", "GenreName", genreMovie.GenreID); ViewData["MovieID"] = new SelectList(_context.movies, "MovieID", "Title", genreMovie.MovieID); return(View(genreMovie)); }
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 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 ActionResult Delete(GenreMovie requestGenreMovie, string Group) { GenreMovie gm = dgm.GenreMovies.Where(p => p.GenreId == requestGenreMovie.GenreId && p.MovieId == requestGenreMovie.MovieId).FirstOrDefault(); dgm.GenreMovies.Remove(gm); dgm.SaveChanges(); if (Group.Equals("Genre")) { return(RedirectToAction("Edit", Group, new { id = requestGenreMovie.GenreId })); } else { return(RedirectToAction("Edit", Group, new { id = requestGenreMovie.MovieId })); } }
public ActionResult Edit(Movie movie, int GenreId) { // Item previousItem = _db.movies.Include(movies => movies.Categories).ThenInclude(join => join.Genre).FirstOrDefault(items => items.ItemId == item.ItemId); GenreMovie join = _db.GenreMovie.FirstOrDefault(genMovie => genMovie.GenreId == GenreId && genMovie.MovieId == movie.MovieId); if (GenreId != 0 && join == null) { _db.GenreMovie.Add(new GenreMovie() { GenreId = GenreId, MovieId = movie.MovieId }); } _db.Entry(movie).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); }
private async Task <bool> UpdateGenreMovieAsync(int id, MovieUpsertRequest req, Movie movie) { movie = await _unit.Movies.GetByIdWithGenresAsync(id); foreach (var genreId in req.Genres) { GenreMovie genreMovie = movie.GenreMovies.FirstOrDefault(x => x.GenreId == genreId); if (genreMovie == null) { await _genreMovieRepo.InsertAsync(new GenreMovie { MovieId = id, GenreId = genreId }); } } return(true); }
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 })); }
public static void Initialize(KinoContext ctx) { ctx.Database.EnsureCreated(); if (ctx.movies.Any()) { return; // DB has been seeded } var genres = new Genre[] { new Genre { GenreName = "Action" }, new Genre { GenreName = "Horror" }, new Genre { GenreName = "Drama" }, new Genre { GenreName = "Comedy" }, new Genre { GenreName = "Animation" }, new Genre { GenreName = "Science fiction" }, new Genre { GenreName = "Romance" }, new Genre { GenreName = "Musical" }, new Genre { GenreName = "Thriller" }, new Genre { GenreName = "Horror" } }; ctx.genres.AddRange(genres); ctx.SaveChanges(); var people = new People[] { // The Fast and the Furious: Tokyo Drif new People { Name = "Justin Lin" }, new People { Name = "Lucas Black" }, new People { Name = "Bow Wow" }, // Godzilla: King of the Monsters new People { Name = "Michael Dougherty" }, new People { Name = "Kyle Chandler" }, new People { Name = "Vera Farmiga" }, new People { Name = "Millie Bobby Brown" }, // Anchorman 2: The Legend Continues new People { Name = "Adam McKay" }, new People { Name = "Will Ferrell" }, new People { Name = "Steve Carell" }, // The Hateful Eight new People { Name = "Quentin Tarantino" }, new People { Name = "Samuel L. Jackson" }, new People { Name = "Kurt Russell" }, // Creed new People { Name = "Ryan Coogler" }, new People { Name = "Michael B. Jordan" }, new People { Name = "Sylvester Stallone" }, // Jurassic World new People { Name = "Colin Trevorrow" }, new People { Name = "Chris Pratt" }, new People { Name = "Bryce Dallas Howard" }, // Inside Out new People { Name = "Pete Docter" }, new People { Name = "Amy Poehler" }, new People { Name = "Phyllis Smith" } }; ctx.people.AddRange(people); ctx.SaveChanges(); Room[] rooms = new Room[] { new Room { Name = "Room 1" }, new Room { Name = "Room 2" }, new Room { Name = "Room 3" }, new Room { Name = "Room 4" } }; ctx.rooms.AddRange(rooms); ctx.SaveChanges(); var seats = new Seat[4 * 12 * 30]; int c = 0; for (int room = 0; room <= 3; room++) { for (int row = 1; row <= 12; row++) { for (int number = 1; number <= 30; number++) { seats[c++] = new Seat { Room = rooms[room], Row = row, Number = number }; } } } ctx.seats.AddRange(seats); ctx.SaveChanges(); var movies = new Movie[] { new Movie { Title = "Fast and Furious: Tokyo Drift", Rating = "PG-13", Length = "122", StartDate = new DateTime(2020, 9, 30), EndDate = new DateTime(2021, 1, 23) }, new Movie { Title = "Godzilla: King of the monsters", Rating = "PG-13", Length = "134", StartDate = new DateTime(2020, 9, 21), EndDate = new DateTime(2021, 1, 15) }, new Movie { Title = "Anchorman 2", Rating = "PG-13", Length = "119", StartDate = new DateTime(2020, 8, 3), EndDate = new DateTime(2020, 12, 30) }, new Movie { Title = "Hateful eight", Rating = "R", Length = "168", StartDate = new DateTime(2020, 7, 5), EndDate = new DateTime(2020, 12, 15) }, new Movie { Title = "Creed", Rating = "PG-13", Length = "133", StartDate = new DateTime(2020, 7, 17), EndDate = new DateTime(2020, 12, 11) }, new Movie { Title = "Jurassic World", Rating = "PG-13", Length = "124", StartDate = new DateTime(2020, 6, 9), EndDate = new DateTime(2020, 12, 1) }, new Movie { Title = "Inside Out", Rating = "PG", Length = "95", StartDate = new DateTime(2020, 8, 12), EndDate = new DateTime(2020, 12, 25) } }; ctx.movies.AddRange(movies); ctx.SaveChanges(); // added genres to movies var movieGenres = new GenreMovie[] { new GenreMovie { MovieID = movies.Single(m => m.Title == "Inside Out").MovieID, GenreID = genres.Single(i => i.GenreName == "Action").GenreID }, new GenreMovie { MovieID = movies.Single(m => m.Title == "Fast and Furious: Tokyo Drift").MovieID, GenreID = genres.Single(i => i.GenreName == "Action").GenreID }, new GenreMovie { MovieID = movies.Single(m => m.Title == "Fast and Furious: Tokyo Drift").MovieID, GenreID = genres.Single(i => i.GenreName == "Drama").GenreID }, new GenreMovie { MovieID = movies.Single(m => m.Title == "Godzilla: King of the monsters").MovieID, GenreID = genres.Single(i => i.GenreName == "Science fiction").GenreID }, new GenreMovie { MovieID = movies.Single(m => m.Title == "Godzilla: King of the monsters").MovieID, GenreID = genres.Single(i => i.GenreName == "Action").GenreID }, new GenreMovie { MovieID = movies.Single(m => m.Title == "Anchorman 2").MovieID, GenreID = genres.Single(i => i.GenreName == "Comedy").GenreID }, new GenreMovie { MovieID = movies.Single(m => m.Title == "Hateful eight").MovieID, GenreID = genres.Single(i => i.GenreName == "Drama").GenreID }, new GenreMovie { MovieID = movies.Single(m => m.Title == "Creed").MovieID, GenreID = genres.Single(i => i.GenreName == "Drama").GenreID }, new GenreMovie { MovieID = movies.Single(m => m.Title == "Jurassic World").MovieID, GenreID = genres.Single(i => i.GenreName == "Action").GenreID }, new GenreMovie { MovieID = movies.Single(m => m.Title == "Inside Out").MovieID, GenreID = genres.Single(i => i.GenreName == "Animation").GenreID } }; foreach (GenreMovie gm in movieGenres) { ctx.GenreMovies.Add(gm); } ctx.SaveChanges(); // added actors to movies var actors = new Actors[] { new Actors { MovieID = movies.Single(m => m.Title == "Fast and Furious: Tokyo Drift").MovieID, PeopleID = people.Single(p => p.Name == "Lucas Black").PeopleID }, new Actors { MovieID = movies.Single(m => m.Title == "Fast and Furious: Tokyo Drift").MovieID, PeopleID = people.Single(p => p.Name == "Bow Wow").PeopleID }, new Actors { MovieID = movies.Single(m => m.Title == "Godzilla: King of the monsters").MovieID, PeopleID = people.Single(p => p.Name == "Kyle Chandler").PeopleID }, new Actors { MovieID = movies.Single(m => m.Title == "Godzilla: King of the monsters").MovieID, PeopleID = people.Single(p => p.Name == "Vera Farmiga").PeopleID }, new Actors { MovieID = movies.Single(m => m.Title == "Godzilla: King of the monsters").MovieID, PeopleID = people.Single(p => p.Name == "Millie Bobby Brown").PeopleID }, new Actors { MovieID = movies.Single(m => m.Title == "Anchorman 2").MovieID, PeopleID = people.Single(p => p.Name == "Will Ferrell").PeopleID }, new Actors { MovieID = movies.Single(m => m.Title == "Anchorman 2").MovieID, PeopleID = people.Single(p => p.Name == "Steve Carell").PeopleID }, new Actors { MovieID = movies.Single(m => m.Title == "Hateful eight").MovieID, PeopleID = people.Single(p => p.Name == "Samuel L. Jackson").PeopleID }, new Actors { MovieID = movies.Single(m => m.Title == "Hateful eight").MovieID, PeopleID = people.Single(p => p.Name == "Kurt Russell").PeopleID }, new Actors { MovieID = movies.Single(m => m.Title == "Creed").MovieID, PeopleID = people.Single(p => p.Name == "Michael B. Jordan").PeopleID }, new Actors { MovieID = movies.Single(m => m.Title == "Creed").MovieID, PeopleID = people.Single(p => p.Name == "Sylvester Stallone").PeopleID }, new Actors { MovieID = movies.Single(m => m.Title == "Jurassic World").MovieID, PeopleID = people.Single(p => p.Name == "Chris Pratt").PeopleID }, new Actors { MovieID = movies.Single(m => m.Title == "Jurassic World").MovieID, PeopleID = people.Single(p => p.Name == "Bryce Dallas Howard").PeopleID }, new Actors { MovieID = movies.Single(m => m.Title == "Inside Out").MovieID, PeopleID = people.Single(p => p.Name == "Amy Poehler").PeopleID }, new Actors { MovieID = movies.Single(m => m.Title == "Inside Out").MovieID, PeopleID = people.Single(p => p.Name == "Phyllis Smith").PeopleID } }; foreach (Actors a in actors) { ctx.Actors.Add(a); } ctx.SaveChanges(); // added directors to movies var directors = new Directors[] { new Directors { MovieID = movies.Single(m => m.Title == "Fast and Furious: Tokyo Drift").MovieID, PeopleID = people.Single(p => p.Name == "Justin Lin").PeopleID }, new Directors { MovieID = movies.Single(m => m.Title == "Godzilla: King of the monsters").MovieID, PeopleID = people.Single(p => p.Name == "Michael Dougherty").PeopleID }, new Directors { MovieID = movies.Single(m => m.Title == "Anchorman 2").MovieID, PeopleID = people.Single(p => p.Name == "Adam McKay").PeopleID }, new Directors { MovieID = movies.Single(m => m.Title == "Hateful eight").MovieID, PeopleID = people.Single(p => p.Name == "Quentin Tarantino").PeopleID }, new Directors { MovieID = movies.Single(m => m.Title == "Creed").MovieID, PeopleID = people.Single(p => p.Name == "Ryan Coogler").PeopleID }, new Directors { MovieID = movies.Single(m => m.Title == "Jurassic World").MovieID, PeopleID = people.Single(p => p.Name == "Colin Trevorrow").PeopleID }, new Directors { MovieID = movies.Single(m => m.Title == "Inside Out").MovieID, PeopleID = people.Single(p => p.Name == "Pete Docter").PeopleID }, }; foreach (Directors d in directors) { ctx.Directors.Add(d); } ctx.SaveChanges(); /* Admin role */ ctx.Roles.Add(new IdentityRole { Id = "1", Name = "Administrator" }); /* Admin user */ var userAdmin = new AppUser { FirstName = "Gospod", LastName = "Admin", NormalizedEmail = "*****@*****.**", Email = "*****@*****.**", UserName = "******", NormalizedUserName = "******", PhoneNumber = "+111111111111", EmailConfirmed = true, PhoneNumberConfirmed = true, SecurityStamp = Guid.NewGuid().ToString("D") }; if (!ctx.Users.Any(u => u.UserName == userAdmin.UserName)) { var password = new PasswordHasher <AppUser>(); var hashed = password.HashPassword(userAdmin, "Geslogeslo1!"); userAdmin.PasswordHash = hashed; ctx.Users.Add(userAdmin); } ctx.SaveChanges(); /* Add user role */ ctx.UserRoles.Add(new IdentityUserRole <string> { RoleId = "1", UserId = userAdmin.Id }); ctx.SaveChanges(); /* Normal user */ var userNormal = new AppUser { FirstName = "Gospod", LastName = "Navadnik", NormalizedEmail = "*****@*****.**", Email = "*****@*****.**", UserName = "******", NormalizedUserName = "******", PhoneNumber = "+111111111111", EmailConfirmed = true, PhoneNumberConfirmed = true, SecurityStamp = Guid.NewGuid().ToString("D") }; if (!ctx.Users.Any(u => u.UserName == userNormal.UserName)) { var password = new PasswordHasher <AppUser>(); var hashed = password.HashPassword(userNormal, "Geslogeslo1!"); userNormal.PasswordHash = hashed; ctx.Users.Add(userNormal); } ctx.SaveChanges(); }
public void EditMovie( Guid id, string name, DateTime year, double rating, string videoPath, string posterPath, string trailerPath, string summary, List <PriceServiceModel> prices, List <GenreServiceModel> genres) { Movie movie = this.Db.Movies.Find(id); movie.Name = name; movie.Year = year; movie.Rating = rating; movie.VideoPath = videoPath != null ? videoPath : movie.VideoPath; if (trailerPath != movie.TrailerPath) { trailerPath = trailerPath.Replace(YoutubeStringForReplace, YoutubeStringReplace); } movie.TrailerPath = trailerPath; movie.PosterPath = posterPath; movie.Summary = summary; foreach (GenreServiceModel genre in genres) { GenreMovie genreMovieDb = this.Db.GenreMovies.Find(genre.Id, movie.Id); if (genreMovieDb == null && genre.IsSelected) { GenreMovie genreMovie = new GenreMovie { GenreId = genre.Id, MovieId = movie.Id }; this.Db.GenreMovies.Add(genreMovie); } else if (genreMovieDb != null && !genre.IsSelected) { this.Db.GenreMovies.Remove(genreMovieDb); } } List <Price> pricesDb = this.Db.Prices.Where(x => x.MovieId == movie.Id).ToList(); foreach (Price price in pricesDb) { price.MoviePrice = prices.First(p => p.Id == price.Id && p.RoleId == price.RoleId).Price; this.Db.Prices.Update(price); } this.Db.Movies.Update(movie); this.Db.SaveChanges(); }
public static void UpdateGenreMovie(this GenreMovie genreMovie, GenreMovieViewModel genreMovieView) { genreMovie.MovieId = genreMovieView.MovieId; genreMovie.GenreId = genreMovieView.GenreId; }
public IActionResult PutClient(long id, GenreMovie item) { return(Ok()); }
public ActionResult <GenreMovie> PostClient(GenreMovie item) { return(Ok()); }
public void Update(GenreMovie updGenreMovie) { db.GenreMovie.Update(updGenreMovie); db.SaveChanges(); }
public async Task <ActionResult <MovieModel> > Post(MovieModel model) { try { var existing = _movieRepository.CheckForExistingMovie(model.Title); if (existing) { return(BadRequest($"The movie title, {model.Title}, already exists in database.")); } var movie = _mapper.Map <Movie>(model); movie.Id = await _movieRepository.GenerateMovieId(); var location = _linkGenerator.GetPathByAction("Get", "Movies", new { movieId = movie.Id }); if (string.IsNullOrWhiteSpace(location)) { return(BadRequest("Could not generate a movie id.")); } if (model.Rating != null) { var rating = await _ratingRepository.GetRatingByIdAsync(model.Rating.Id); if (rating == null) { return(BadRequest($"The rating id, {model.Rating.Id}, does not exist.")); } movie.Rating = rating; } if (model.MovieGenres != null) { var movieGenres = new List <GenreMovie>(); foreach (var movieGenre in model.MovieGenres) { var genre = await _genreRepository.GetGenreAsync(movieGenre.GenreId); if (genre == null) { return(BadRequest($"The genre id, {movieGenre.GenreId}, does not exist.")); } var mg = new GenreMovie { GenreId = genre.Id, MovieId = model.Id }; movieGenres.Add(mg); } movie.MovieGenres = movieGenres; } if (model.MovieActors != null) { var movieActors = new List <ActorMovie>(); foreach (var movieActor in model.MovieActors) { var actorMovie = await this.GetMovieActorActionResult(movieActor, model.Id); if (actorMovie == null) { return(BadRequest($"Could not add actor {movieActor.LastName}, {movieActor.FirstName}")); } movieActors.Add(actorMovie); } movie.MovieActors = movieActors; } if (model.MovieDirectors != null) { var movieDirectors = new List <DirectorMovie>(); foreach (var movieDirector in model.MovieDirectors) { var directorMovie = await this.GetMovieDirectorActionResult(movieDirector, model.Id); if (directorMovie == null) { return(BadRequest($"Could not add director {movieDirector.LastName}, {movieDirector.FirstName}")); } movieDirectors.Add(directorMovie); } movie.MovieDirectors = movieDirectors; } if (model.MovieStudios != null) { var movieStudios = new List <StudioMovie>(); foreach (var movieStudio in model.MovieStudios) { var studioMovie = await this.GetMovieStudioActionResult(movieStudio, model.Id); if (studioMovie == null) { return(BadRequest($"Could not add the studio, {movieStudio.Name}")); } movieStudios.Add(studioMovie); } movie.MovieStudios = movieStudios; } _movieRepository.Add(movie); if (await _movieRepository.SaveChangesAsync()) { return(Created(location, _mapper.Map <MovieModel>(movie))); } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } return(BadRequest()); }
public void Add(GenreMovie newGenreMovie) { db.GenreMovie.Add(newGenreMovie); db.SaveChanges(); }