//Create get public IActionResult Edit(int Id) { MovieVM movieVM = new MovieVM() { Movie = _db.Movie.Find(Id), DirectorSelectList = _db.Director.Select(i => new SelectListItem { Text = i.FirstName + " " + i.LastName, Value = i.Id.ToString() }), MovieStudioSelectList = _db.MovieStudio.Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }) }; if (movieVM.Movie == null) { return(NotFound()); } else { return(View(movieVM)); } }
//Create post public IActionResult Edit(MovieVM movieVM) { var files = HttpContext.Request.Form.Files; string webRootPath = _webHostEnvironment.WebRootPath; var objFromDb = _db.Movie.AsNoTracking().FirstOrDefault(m => m.Id == movieVM.Movie.Id); if (files.Count > 0) { string upload = webRootPath + WebConstants.ImageMoviePath; string fileName = Guid.NewGuid().ToString(); string extension = Path.GetExtension(files[0].FileName); var oldFile = Path.Combine(upload, objFromDb.Image); if (System.IO.File.Exists(oldFile)) { System.IO.File.Delete(oldFile); } using (var fileStream = new FileStream(Path.Combine(upload, fileName + extension), FileMode.Create)) { files[0].CopyTo(fileStream); } movieVM.Movie.Image = fileName + extension; } else { movieVM.Movie.Image = objFromDb.Image; } _db.Movie.Update(movieVM.Movie); _db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Upsert(int?id) { IEnumerable <Category> listOfCategories = await _unitOfWork.Category.GetAllAsync(); MovieVM movieVM = new MovieVM() { Movie = new Movie(), CategoryList = listOfCategories.Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }), DeliveryTypeList = _unitOfWork.DeliveryType.GetAll().Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }) }; if (id == null) { //create return(View(movieVM)); } movieVM.Movie = _unitOfWork.Movie.Get(id.GetValueOrDefault()); if (movieVM.Movie == null) { return(NotFound()); } return(View(movieVM)); }
public IActionResult Index(string searchTitle) { MovieVM model = new MovieVM(); model.Movies = _movieRepository.Movies(searchTitle); return(View(model)); }
public IActionResult Movie() { MovieVM model = new MovieVM(); model.Movies = _movieRepository.Movies(string.Empty); return(View(model)); }
public ActionResult Save(Movie movie) { if (!ModelState.IsValid) { var viewModel = new MovieVM(movie) { Genres = _context.Genres.ToList() }; return(View("MovieForm", viewModel)); } //new movie if (movie.Id == 0) { movie.DateAdded = DateTime.Now; movie.NumberAvailable = movie.NumberInStock; _context.Movies.Add(movie); } else { var movieInDB = _context.Movies.Single(c => c.Id == movie.Id); movieInDB.Name = movie.Name; movieInDB.ReleaseDate = movie.ReleaseDate; movieInDB.NumberInStock = movie.NumberInStock; movieInDB.NumberAvailable = movie.NumberInStock; movieInDB.GenreId = movie.GenreId; } _context.SaveChanges(); return(RedirectToAction("Index", "Movie")); }
public HttpStatusCodeResult NewMovie(MovieVM movieVM) { Movie Movie = new Movie { Name = movieVM.Name, Plot = movieVM.Plot, Poster = movieVM.Poster, ProducerID = movieVM.ProducerID }; DB.Movies.Add(Movie); DB.SaveChanges(); foreach (var Actor in movieVM.ActorList) { ActorMovie AM = new ActorMovie { ActorID = Actor, MovieID = Movie.ID }; DB.ActorsMovies.Add(AM); } DB.SaveChanges(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public void AddNewMovie(MovieVM movie) { var result = true; int userId = 2; base.MovieService.CreateNewMovie(userId, movie.title, movie.description, movie.genre, DateTime.Now, movie.starring, movie.imageurl); }
public HttpStatusCodeResult EditMovie(MovieVM movieVM) { if (movieVM != null) { Movie Movie = DB.Movies.Where(m => m.ID == movieVM.ID).FirstOrDefault(); Movie.Name = movieVM.Name; Movie.Plot = movieVM.Plot; Movie.Poster = movieVM.Poster ?? Movie.Poster; Movie.ProducerID = movieVM.ProducerID; IEnumerable <ActorMovie> ActMov = DB.ActorsMovies.Where(a => a.MovieID == movieVM.ID); DB.ActorsMovies.RemoveRange(ActMov); foreach (var Actor in movieVM.ActorList) { ActorMovie AM = new ActorMovie { ActorID = Actor, MovieID = Movie.ID }; DB.ActorsMovies.Add(AM); } DB.SaveChanges(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } }
public async Task <ActionResult <MovieVM> > CreateMovie(MovieVM movieVM) { try { if (movieVM == null) { return(BadRequest()); } // Add custom model validation error Movie movie = await movieRepository.GetMovieById(movieVM.Movie); if (movie != null) { ModelState.AddModelError("Video Id", $"Video Id: {movieVM.Movie.MovieId} already in use"); return(BadRequest(ModelState)); } await movieRepository.CreateMovie(movieVM); return(CreatedAtAction(nameof(GetMovie), new { id = movieVM.Movie.Id }, movieVM)); } catch (DbUpdateException Ex) { return(StatusCode(StatusCodes.Status500InternalServerError, Ex.InnerException.Message)); } }
public MovieVM GetById(int id) { Movie m = new MovieRepository().GetById(id); MovieVM mVM = new MovieVM(m.Id, m.Name, m.PriceId); return(mVM); }
public ActionResult <MovieVM> Post(MovieVM movieVM) { if (movieVM.Id == 0) { var movie = new Movie { Name = movieVM.Name, GenreId = movieVM.GenreId, DateRelease = movieVM.DateRelease }; _context.Movies.Add(movie); } else { var movieInDb = _context.Movies.Find(movieVM.Id); movieInDb.Name = movieVM.Name; movieInDb.GenreId = movieVM.GenreId; movieInDb.DateRelease = movieVM.DateRelease; } _context.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Movies/Delete/5 public ActionResult Delete(int id) { MovieVM movieVM = new MovieVM(); using (MoviesReference.MoviesClient service = new MoviesReference.MoviesClient()) { MoviesReference.MovieDto movieDto = service.GetMovieByID(id); movieVM = new MovieVM { Id = movieDto.Id, Title = movieDto.Title, ReleaseDate = movieDto.ReleaseDate, ReleaseCountry = movieDto.ReleaseCountry, GenreId = movieDto.Genre.Id, GenreVM = new GenreVM { Id = movieDto.Genre.Id, Name = movieDto.Genre.Name } }; } return(View(movieVM)); }
public ActionResult Create(MovieVM movieVM) { try { using (MoviesReference.MoviesClient service = new MoviesReference.MoviesClient()) { MoviesReference.MovieDto movieDto = new MoviesReference.MovieDto { Title = movieVM.Title, ReleaseDate = movieVM.ReleaseDate, ReleaseCountry = movieVM.ReleaseCountry, Genre = new MoviesReference.GenreDto { Id = movieVM.GenreId } }; service.PostMovie(movieDto); } using (GenresReference.GenresClient service = new GenresReference.GenresClient()) { ViewBag.Genres = new SelectList(service.GetGenres(), "Id", "Name"); } return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(MovieVM movieVM) { try { if (ModelState.IsValid) { using (MoviesReference.MoviesClient service = new MoviesReference.MoviesClient()) { MoviesReference.MovieDto movieDto = new MoviesReference.MovieDto { Title = movieVM.Title, ReleaseDate = movieVM.ReleaseDate, ReleaseCountry = movieVM.ReleaseCountry, Genre = new MoviesReference.GenreDto { Id = movieVM.GenreId } }; service.PostMovie(movieDto); } return(RedirectToAction("Index")); } ViewBag.Genres = LoadDataUtil.LoadGenreData(); return(View()); } catch { ViewBag.Genres = LoadDataUtil.LoadGenreData(); return(View()); } }
public async Task <IActionResult> Create(MovieVM movie) { if (ModelState.IsValid) { var client = _httpClientFactory.CreateClient("MMDB_API"); string uniqueFileName = UploadedFile(movie); MoviePutVM moviePost = new MoviePutVM { Title = movie.Title, Description = movie.Description, ReleaseDate = movie.ReleaseDate, DirectorId = movie.DirectorId, Poster = uniqueFileName }; var movieContent = new StringContent(JsonSerializer.Serialize(moviePost), Encoding.UTF8, "application/json"); var response = await client.PostAsync("movies", movieContent).ConfigureAwait(false); if (response.IsSuccessStatusCode) { return(RedirectToAction(nameof(Index))); } return(RedirectOnError(response, "Create", "create an movie", "creating an movie")); } return(View(movie)); }
public void OnGet(MovieVM testMovie) { AllGenreNames = new List <string>(); Movie = _db.Movies.Where(movie => movie.Id == testMovie.Id).FirstOrDefault(); Movie.PosterPath = "https://image.tmdb.org/t/p/w500" + Movie.PosterPath; Genre = _db.Genres.Where(genre => genre.GenreId == Movie.GenreId).FirstOrDefault(); AllGenres = _db.MovieGenres.Where(genre => genre.MovieId == Movie.MovieId).ToList(); for (var i = 0; i < AllGenres.Count; i++) { string name = null; Genre = _db.Genres.Where(genre => genre.GenreId == AllGenres[i].GenreId).FirstOrDefault(); if (i == AllGenres.Count - 1) { name = Genre.Name; } else { name = Genre.Name + ", "; } AllGenreNames.Add(name); } }
public bool Save(MovieVM movie) { if (movie.MovieId > 0) // update { Movie movieToBeUpdated = _context.Movie.Find(movie.MovieId); movieToBeUpdated.MovieTitle = movie.MovieTitle; movieToBeUpdated.MovieDescription = movie.MovieDescription; movieToBeUpdated.IsRented = movie.IsRented; movieToBeUpdated.RentalDate = Convert.ToDateTime(movie.RentalDate); _context.Entry(movieToBeUpdated).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } else // create { _context.Movie.Add(new Movie() { MovieTitle = movie.MovieTitle, MovieDescription = movie.MovieDescription, IsRented = movie.IsRented, RentalDate = Convert.ToDateTime(movie.RentalDate), }); } return(_context.SaveChanges() > 0); }
public ActionResult Edit(MovieVM movie) { if (ModelState.IsValid) { // borrar MovieActors where MovieId == movie.Id var query = from m in db.MovieActors where m.MovieId == movie.Id select m; foreach (var item in query) { db.Entry(item).State = EntityState.Deleted; } foreach (var item in movie.ActorSelector) { if (item.Selected) { db.MovieActors.Add(new MovieActors() { ActorId = item.Id, MovieId = movie.Id }); } } //db.Entry(movie).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DirectorId = new SelectList(db.Director, "Id", "Name", movie.DirectorId); ViewBag.MediaId = new SelectList(db.RelatedMedia, "Id", "MediaLink", movie.MediaId); return(View(movie)); }
private MovieVM GetMovieModel() { MovieVM model = new MovieVM(); model.Movies = _movieRepository.Movies(string.Empty); return(model); }
public async Task <IActionResult> Details(int id) { MovieVM movie; var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:55169/api/Movies/" + id); request.Headers.Add("Accept", "application/json"); var client = _httpClientFactory.CreateClient(); var response = await client.SendAsync(request).ConfigureAwait(false); if (response.IsSuccessStatusCode) { using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); movie = await JsonSerializer.DeserializeAsync <MovieVM>(responseStream); } else { movie = new MovieVM(); } return(View(movie)); }
public async Task <IActionResult> Edit(int id, MovieVM movie) { if (movie.MovieGenreDTOs == null) { movie.MovieGenreDTOs = new MovieGenreVM[0]; } if (movie.MovieActorDTOs == null) { movie.MovieActorDTOs = new MovieActorVM[0]; } if (ModelState.IsValid) { var client = _httpClientFactory.CreateClient(); var movieContent = new StringContent(JsonSerializer.Serialize(movie), Encoding.UTF8, "application/json"); HttpResponseMessage httpResponseMessage = await client.PutAsync(new Uri("http://localhost:55169/api/Movies/" + id), movieContent).ConfigureAwait(false); if (httpResponseMessage.IsSuccessStatusCode) { return(RedirectToAction(nameof(Index))); } } return(View(movie)); }
public IActionResult OnPost(MovieVM testMovie, string returnUrl = null, string favUrl = null) { int? favouriteId = HttpContext.Session.GetInt32("favouriteId"); bool isUser = _signInManager.IsSignedIn(User); string userId = null; returnUrl = returnUrl ?? Url.Content("/Identity/Account/Login"); favUrl = favUrl ?? Url.Content("/MovieFavourites/MovieFavourites"); if (isUser) { userId = _userManager.FindByNameAsync(User.Identity.Name).Result.Id; } else { return(LocalRedirect(returnUrl)); } Favourite fav; if (favouriteId == null) { fav = new Favourite(userId, DateTime.Now); _db.Favourites.Add(fav); _db.SaveChanges(); favouriteId = fav.Id; } else { Favourite = _db.Favourites .Include(f => f.FavouriteMovies) .ThenInclude(fm => fm.Movie) .Where(f => f.Id == (int)HttpContext.Session.GetInt32("favouriteId")) .FirstOrDefault(); if (Favourite.UserId != userId) { fav = new Favourite(userId, DateTime.Now); _db.Favourites.Add(fav); _db.SaveChanges(); favouriteId = fav.Id; } } FavouriteMovie fm; fm = _db.FavouriteMovies.Where(fm => fm.FavouriteId == favouriteId && fm.MovieId == testMovie.Id).FirstOrDefault(); if (fm == null) { fm = new FavouriteMovie((int)favouriteId, testMovie.Id); _db.FavouriteMovies.Add(fm); } _db.SaveChanges(); HttpContext.Session.SetInt32("favouriteId", (int)favouriteId); return(LocalRedirect(favUrl)); }
public async Task <IActionResult> Edit(int id) { if (!HttpContext.Session.Keys.Contains("actors")) { using var actorsRequest = new HttpRequestMessage(HttpMethod.Get, "http://localhost:55169/api/Actors"); actorsRequest.Headers.Add("Accept", "application/json"); var actorsClient = _httpClientFactory.CreateClient(); var actorsResponse = await actorsClient.SendAsync(actorsRequest).ConfigureAwait(false); if (actorsResponse.IsSuccessStatusCode) { string responseString = await actorsResponse.Content.ReadAsStringAsync().ConfigureAwait(false); HttpContext.Session.SetString("actors", responseString); } } if (!HttpContext.Session.Keys.Contains("genres")) { using var genresRequest = new HttpRequestMessage(HttpMethod.Get, "http://localhost:55169/api/Genres"); genresRequest.Headers.Add("Accept", "application/json"); var genresClient = _httpClientFactory.CreateClient(); var genresResponse = await genresClient.SendAsync(genresRequest).ConfigureAwait(false); if (genresResponse.IsSuccessStatusCode) { string responseString = await genresResponse.Content.ReadAsStringAsync().ConfigureAwait(false); HttpContext.Session.SetString("genres", responseString); } } MovieVM movie; var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:55169/api/Movies/" + id); request.Headers.Add("Accept", "application/json"); var client = _httpClientFactory.CreateClient(); var response = await client.SendAsync(request).ConfigureAwait(false); if (response.IsSuccessStatusCode) { using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); movie = await JsonSerializer.DeserializeAsync <MovieVM>(responseStream); } else { movie = new MovieVM(); } return(View(movie)); }
public MovieVM getGenresJob() { MovieVM model = new MovieVM(); model.genres = _context.Genres.Where(x => x.IsDeleted == false).ToList(); model.personJobs = _context.PersonJobs.Include(q => q.Person).Where(x => x.IsDeleted == false).ToList(); return(model); }
/// <summary> /// Add new /// </summary> /// <param name="entity">corresponding entity</param> public void Add(MovieVM movieVM) { Movie movie = new Movie(); movie.Name = movieVM.Name; movie.PriceId = movieVM.PriceId; new MovieRepository().Add(movie); }
public IActionResult Save([FromBody] MovieVM movie) { return(Ok(new APIResponseVM() { Status = _movieRepository.Save(movie), Message = "Success" })); }
public async Task <MovieVM> GetMovie(int id) { MovieVM movieVM = new MovieVM(); movieVM.Movie = await appDbContext.Movies.FirstOrDefaultAsync(e => e.Id == id); return(movieVM); }
public IActionResult Index() { MovieVM model = new MovieVM(); model.Movies = _movieRepository.Movies; return(View(model)); }
public static void OnMovieShowing(Movie brand) { MovieVM brandVM = new MovieVM(brand, true); if (ShowMovie != null) { ShowMovie.Invoke(brandVM); } }
private void MovieVMToMovieNavigationProps(MovieVM model, Movie movie) { HashSet<Actor> actors = new HashSet<Actor>(); if (model.Actors != null) { foreach (var act in model.Actors) { var currentActor = db.Actors.All().FirstOrDefault(a => a.Id == act.Id); if (currentActor != null) { actors.Add(currentActor); } } } movie.Actors = actors; if (model.Category != null) { var currentCategory = db.Categories.All().FirstOrDefault(c => c.Id == model.Category.Id); if (currentCategory != null) { movie.Category = currentCategory; } else { movie.Category = db.Categories.All().First(); } } else { movie.Category = db.Categories.All().First(); } if (model.Country != null) { var currentCountry = db.Country.All().FirstOrDefault(c => c.Id == model.Country.Id); if (currentCountry != null) { movie.Country = currentCountry; } else { movie.Country = db.Country.All().First(); } } else { movie.Country = db.Country.All().First(); } if (model.Director != null) { var currentDirector = db.Directors.All().FirstOrDefault(c => c.Id == model.Director.Id); if (currentDirector != null) { movie.Director = currentDirector; } else { movie.Director = db.Directors.All().First(); } } else { movie.Director = db.Directors.All().First(); } }
public ActionResult Create([DataSourceRequest]DataSourceRequest request, MovieVM model) { if (ModelState.IsValid) { Movie movie = new Movie(); movie = MovieVM.ToMovieSimple(movie, model); MovieVMToMovieNavigationProps(model, movie); model = new MovieVM() { Id = movie.Id, Title = movie.Title, Category = new CategoryVM() { Id = movie.Category.Id, Name = movie.Category.Name }, CategoryName = movie.Category.Name, DirectorName = movie.Director.FirstName + " " + movie.Director.LastName, Director = new DirectorVM() { Id = movie.Director.Id, Name = movie.Director.FirstName + " " + movie.Director.LastName, }, Actors = movie.Actors.Select(a => new ActorVM() { Id = a.Id, Name = a.FirstName + " " + a.LastName, }), Country = new CountryVM() { Id = movie.Country.Id, Name = movie.Country.Name, }, CountryName = movie.Country.Name, ParentsGuideId = (int)(movie.ParentsGuide), Poster = movie.Poster, Year = movie.Year, Duration = movie.Duration, Description = movie.Description, }; model.ParentsGuideName = Enum.GetName(typeof(ParentsGuide), model.ParentsGuideId); try { db.Movies.Add(movie); db.SaveChanges(); } catch (Exception ex) { ModelState.AddModelError("DatabaseException", "Database error while updating the entries. Try updating again." + ex.Message); } } return Json((new[] { model }.ToDataSourceResult(request, ModelState)), JsonRequestBehavior.AllowGet); }
public ActionResult Edit([DataSourceRequest] DataSourceRequest request, MovieVM model) { var movie = db.Movies.All().Include(a => a.Actors).ToList().FirstOrDefault(m => m.Id == model.Id); if (movie != null) { movie = MovieVM.ToMovieSimple(movie, model); MovieVMToMovieNavigationProps(model, movie); } else { ModelState.AddModelError("Movie", "Movie not found! Updating failed."); } if (ModelState.IsValid) { try { db.SaveChanges(); } catch (Exception ex) { ModelState.AddModelError("DatabaseException", "Database error while updating the entries. Try updating again." + ex.Message); } } return Json((new[] { model }.ToDataSourceResult(request, ModelState)), JsonRequestBehavior.AllowGet); }