private void ViewModel_AddingMovie(object sender, EventArgs e) { _addMovieViewModel = new AddMovieViewModel(_service); _addMovieView = new AddMovie { DataContext = _addMovieViewModel }; _addMovieViewModel.StartingImageChange += ViewModel_StartingImageChange; _addMovieViewModel.AddingMovieEnded += ViewModel_AddingMovieEnded; _addMovieView.ShowDialog(); }
public ActionResult Add() { List <Actors> actor = actorsRepository.ListActors(); List <Producers> producers = producersRepository.ListProducers(); var viewModel = new AddMovieViewModel { Actors = actor, Prod = producers }; return(View(viewModel)); }
public async Task <IActionResult> AddMovie(AddMovieViewModel model) { if (!ModelState.IsValid) { var categories = await this._categories.GetAllCategories(); model.Categories = this.GetCategories(categories); return(View(model)); } if (await this._movies.IsMovieExist(model.Title, model.Year, model.ReleaseDate)) { TempData.AddErrorMessage($"Movie {model.Title} is already uploaded!"); var categories = await this._categories.GetAllCategories(); model.Categories = GetCategories(categories); return(View(model)); } foreach (var categoryName in model.SelectedCategories) { if (!await this._categories.CategoryExistsAsync(categoryName)) { return(BadRequest()); } } var isUserInRoleModerator = User.IsInRole(RoleConstants.ModeratorRole); var userId = _userManager.GetUserId(User); var movieId = await this._movies.AddMovieAsunc( model.Title, model.Year, model.Duration, model.Plot, model.TrailerUrl, model.ImageUrl, model.ParrentControl, model.ReleaseDate, model.SelectedCategories, model.Actiors, model.Writers, model.Director, isUserInRoleModerator, userId ); TempData.AddSuccessMessage($"Movie {model.Title} is successfuly uploaded!"); return(RedirectToAction("MoviePreview", "Movies", new { area = "", movieId = movieId })); }
public void AddCommand_ShouldBeEnabled_IfNameAndImageUrlAreNotEmpty() { // Arrange _target = new AddMovieViewModel(_schedulerService, _viewStackService.Object, _moviesServiceMock.Object); // Act _target.Activator.Activate(); _target.Name = "Name"; _target.ImageUrl = "ImageUrl"; _schedulerService.AdvanceBy(1000); // Assert _target.AddMovie.CanExecute.Subscribe(canExecute => Assert.IsTrue(canExecute)); }
public ActionResult AddMovie(AddMovieViewModel model) { var movie = new EntityFrameworkIntro.Models.Movie(); movie.Title = model.Title; movie.GenreId = model.GenreId; movie.RatingId = model.RatingsId; var repository = new MovieCatalogEntities(); repository.Movies.Add(movie); repository.SaveChanges(); return(RedirectToAction("Index", new { id = movie.MovieId })); }
private void EraseGenres(AddMovieViewModel vm, int filmId) { // Deletes any existing FilmGenres that are no longer selected for this film. List <FilmGenre> thisFilmGenres = _context.FilmGenres.Include(fg => fg.Genre).Where(fg => fg.FilmID == filmId).ToList(); // Eliminate any previous FilmGenres that weren't selected in an edit foreach (FilmGenre filmGenre in thisFilmGenres) { if (!vm.Genres.Contains(filmGenre.Genre.ID.ToString())) { _context.FilmGenres.Remove(filmGenre); } } }
public JsonResult AddActor(AddMovieViewModel actor) { try { var newActor = new Actors() { Name = actor.AName, Bio = actor.ABio, Dob = actor.ADob, Sex = actor.ASex, }; actor.AId = actorsRepository.AddActor(newActor); } catch (Exception e) { string s = e.HelpLink; } return(Json(actor)); }
//[ValidateAntiForgeryToken] public IActionResult Add() { AddMovieViewModel model = new AddMovieViewModel(); try { return(View(model)); } catch (Exception ex) { _logger.Error(ex, "Error occured"); _commonFunction.LogException(ex); } // model.AllGenre = GetAllGenre(); return(View(model)); }
public void WhenExecuted_CheckIfPopPageIsCalled() { // Arrange _target = new AddMovieViewModel(_schedulerService, _viewStackService.Object, _moviesServiceMock.Object); _target.Name = "Name"; _target.ImageUrl = "ImageUrl"; // Act Observable.Return(Unit.Default).InvokeCommand(_target.AddMovie); // Assert _moviesServiceMock .Verify(x => x.Create( It.IsAny <CreateMovieRequestDTO>()), Times.Once); }
public ActionResult Edit([Bind(Include = "MovieId,Title,Year,Price,ImageUrl,TrailerUrl,GenreId")] Movie movie) { if (ModelState.IsValid) { _movieServiceGateway.Update(movie); return(RedirectToAction("Index")); } var model = new AddMovieViewModel() { Movie = movie, Genres = _genreServiceGateway.Read() }; return(View(model)); }
public ActionResult AddMovie() { var genresSelectList = this.genreService .GetAllGenres() .Select(g => new SelectListItem() { Text = g.Name, Value = g.Name }); var movieViewModel = new AddMovieViewModel() { GenresSelectList = genresSelectList }; return(this.PartialView(PartialViews.AddMovie, movieViewModel)); }
public ActionResult AddMovie() { var repository = new MovieCatalogEntities(); AddMovieViewModel model = new AddMovieViewModel(); model.Genres = from g in repository.Genres select new SelectListItem { Text = g.GenreType, Value = g.GenreId.ToString() }; model.Ratings = from r in repository.Ratings select new SelectListItem { Text = r.RatingName, Value = r.RatingId.ToString() }; return(View(model)); }
public ActionResult Edit(Guid?id) { AddMovieViewModel model; if (id == null) { model = new AddMovieViewModel(); } else { var movie = _movieService.GetById(id.GetValueOrDefault()); model = _mapper.Map <AddMovieViewModel>(movie); } model.Genres = _genreService.GetAll(); model.Actors = _actorService.GetAll(); return(View(model)); }
public JsonResult AddProducer(AddMovieViewModel producer) { try { var newProducer = new Producers() { Name = producer.AName, Bio = producer.ABio, Dob = producer.ADob, Sex = producer.ASex, }; producer.AId = producersRepository.AddProducer(newProducer); } catch (Exception e) { string s = e.HelpLink; } return(Json(producer)); }
public ActionResult Edit(AddMovieViewModel model) { var movie = _mapper.Map <MovieModel>(model); movie.Poster = new MediaModel { Link = model.PosterLink, Type = MediaType.Poster }; if (model.SelectedGenres != null) { movie.Genres = _genreService.GetByIds(model.SelectedGenres); } if (model.SelectedActors != null) { movie.Actors = _actorService.GetByIds(model.SelectedActors); } _movieService.AddOrUpdate(movie, model.SelectedGenres, model.SelectedActors); return(RedirectToAction("Index", "Movie")); }
public void OnlyRedirect_WhenModelStateIsValid() { // Arrange var movieViewModel = new AddMovieViewModel() { }; var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(movieViewModel, null, null); var results = new List <ValidationResult>(); // Act var isModelValid = Validator.TryValidateObject(movieViewModel, validationContext, results); // Assert Assert.IsFalse(isModelValid); }
public async Task <IActionResult> Add(AddMovieViewModel vm) { // If the model is valid, create a new film and add it to the database. If // it's not valid, return to the view. if (ModelState.IsValid) { ApplicationUser user = _context.Users.Single(u => u.Id == _userManager.GetUserId(User)); Film film = new Film(); film.User = user; int id = await UpdateMovieAsync(vm, film); return(Redirect($"/Movie/ViewMovie/{id}")); } vm.MediaFormats = vm.PopulateList(_context.MediaFormats.ToList()); vm.AudioFormats = vm.PopulateList(_context.AudioFormats.ToList()); return(View(vm)); }
public ActionResult Edit(int id) { var movieInDb = _dbContext.Movies.SingleOrDefault(m => m.Id == id); if (movieInDb == null) { return(HttpNotFound()); } var genres = _dbContext.Genres.ToList(); var viewModel = new AddMovieViewModel() { Movie = movieInDb, Genres = genres, PageName = "Edit Movie" }; return(View("MovieForm", viewModel)); }
// GET: Movies/Edit/5 public ActionResult Modify(int id) { List <Movies> movies = moviesRepository.ListMovie(); Movies selectedmovie = (from m in movies where m.Id == id select m).Single(); List <Producers> producers = producersRepository.ListProducers(); Producers selectedproducer = (from p in producers where p.Id == selectedmovie.ProducerId select p).Single(); List <Actors> actors = actorsRepository.ListActors(); List <Actor_Movies> actor_movies = actor_MoviesRepository.ListActor_Movies(); List <Actors> selectedActors = new List <Actors>(); AddMovieViewModel viewmodel = new AddMovieViewModel(); foreach (Actor_Movies actor_movie in selectedmovie.Actor_movie) { if (actor_movie.MovieId == selectedmovie.Id) { Actors act = (from s in actors where s.Id == actor_movie.ActorId select s).Single(); selectedActors.Add(act); } } string temp = selectedmovie.ReleaseDate.ToString("yyyy-MM-dd"); viewmodel.ReleaseDate = Convert.ToDateTime(temp); viewmodel.Actors = actors; viewmodel.Prod = producers; viewmodel.Plot = selectedmovie.Plot; viewmodel.selectedM = selectedmovie; viewmodel.selectedP = selectedproducer; viewmodel.selectedA = selectedActors; return(View(viewmodel)); }
public IActionResult Add(AddMovieViewModel addMovieViewModel) { if (!ModelState.IsValid) { return(View(addMovieViewModel)); } var destinationDir = Path.Combine("img", "posters"); string posterPath; try { posterPath = fileHelper.Save(addMovieViewModel.Poster, destinationDir); } catch { ModelState.AddModelError("", "W czasie zapisywania plakatu na serwerze, wystąpił błąd."); return(View(addMovieViewModel)); } var movie = new Movie { Title = addMovieViewModel.Title, Description = addMovieViewModel.Description, PosterPath = posterPath, ReleaseDate = addMovieViewModel.ReleaseDate.Value, Country = addMovieViewModel.Country }; try { var movieId = movieRepository.AddMovie(movie); return(RedirectToAction(nameof(Details), new { id = movieId })); } catch { fileHelper.Delete(posterPath); ModelState.AddModelError("", "W czasie dodawania filmu do bazy danych, wystąpił błąd."); return(View(addMovieViewModel)); } }
public ActionResult Create(AddMovieViewModel viewmodel) { try { String s = viewmodel.Name; String path = "C:\\users\\rajat\\source\\repos\\IMBD\\IMBD\\Content\\Posters\\"; //String path = ConfigurationManager.AppSettings["Path"]; // viewmodel.File.SaveAs(path+viewmodel.Id); Image source = Image.FromStream(viewmodel.File.InputStream); var NewMovie = new Movies() { Name = viewmodel.Name, ReleaseDate = viewmodel.ReleaseDate, Plot = viewmodel.Plot, PosterId = 123, ProducerId = viewmodel.producer }; moviesRepository.AddMovie(NewMovie); viewmodel.File.SaveAs(Path.Combine(@path, "" + NewMovie.Id + ".jpg")); foreach (int i in viewmodel.ActorIds) { var actor_mov = new Actor_Movies() { MovieId = NewMovie.Id, ActorId = i }; actor_MoviesRepository.Add(actor_mov); } return(RedirectToAction("Add")); } catch { return(View()); } }
public ActionResult AddMovie([Bind(Exclude = "Image")] AddMovieViewModel movieViewModel) { if (!this.ModelState.IsValid) { return(this.RedirectToAction <PanelController>(c => c.Index())); } if (this.Request.Files.Count > 0) { var image = this.Request.Files["Image"]; var imageData = this.fileConverter.PostedToByteArray(image); movieViewModel.Image = imageData; } var movieModel = this.mapper.Map <Movie>(movieViewModel); this.movieService.AddMovie(movieModel, movieViewModel.GenreName); return(this.RedirectToAction <MoviesGridController>(c => c.Index())); }
public void NotCallAddMethodOfMovieService_WhenModelStateIsInvalid() { var genreServiceMock = new Mock <IGenreService>(); var movieServiceMock = new Mock <IMovieService>(); var personServiceMock = new Mock <IPersonService>(); var fileConverterMock = new Mock <IFileConverter>(); var mapperMock = new Mock <IMapper>(); var movieViewModel = new AddMovieViewModel() { GenreName = "Genre Name" }; var movieDbModel = new Movie() { }; var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(movieViewModel, null, null); var results = new List <ValidationResult>(); var isModelValid = Validator.TryValidateObject(movieViewModel, validationContext, results); var panelController = new PanelController( genreServiceMock.Object, movieServiceMock.Object, personServiceMock.Object, fileConverterMock.Object, mapperMock.Object); panelController.ModelState.AddModelError("name", "No movie name!"); // Act panelController.AddMovie(movieViewModel); // Assert Assert.IsFalse(isModelValid); movieServiceMock.Verify(ms => ms.AddMovie(movieDbModel, movieViewModel.GenreName), Times.Never); }
public async Task <IActionResult> AddMovie([FromForm] AddMovieViewModel movieModel) { // ------- save ImageFile to directory var rootPath = _hostEnvironment.WebRootPath; var fileName = Path.GetFileNameWithoutExtension(movieModel.ImageFile.FileName); var extension = Path.GetExtension(movieModel.ImageFile.FileName); var userPhotoName = fileName + DateTime.Now.ToString("yymmddssfff") + extension; string path = Path.Combine(rootPath, "image", userPhotoName); using (var fileStream = new FileStream(path, FileMode.Create)) { await movieModel.ImageFile.CopyToAsync(fileStream); } // ------- create new movie with current movie data that coming from request body Movie movie = new Movie { Name = movieModel.Name, Description = movieModel.Description, ReleaseDate = Int32.Parse(movieModel.ReleaseDate), Director = movieModel.Director, UserId = new Guid(movieModel.UserId), ImagePath = path, RankCount = 0, }; await _applicationDb.Movies.AddAsync(movie); // await _applicationDb.Movies.AddAsync(movie); await _applicationDb.SaveChangesAsync(); var retrieveMovie = new RetrieveMovieViewModel(movie); return(CreatedAtAction(nameof(GetMovie), new { movieName = retrieveMovie.Name }, retrieveMovie)); }
public IActionResult AddMovie(AddMovieViewModel vm) { if (!this.ModelState.IsValid) { List <Actor> actors = this.actorsService.GetAll().ToList(); List <Genre> genre = this.genreService.GetAll().ToList(); AddMovieViewModel model = new AddMovieViewModel(actors, genre); return(View(model)); } var movies = this.movieService.GetAll(); foreach (var movie in movies) { if (movie.Title.Equals(vm.Title, StringComparison.InvariantCultureIgnoreCase)) { ViewData["MovieExists"] = "A movie with this title already exists!"; return(View(vm)); } } List <Genre> genres = new List <Genre>(); foreach (var g in vm.Genres) { if (g.IsChecked == true) { genres.Add(new Genre { Id = g.Id, Name = g.Name }); } } this.movieService.AddMovie(vm.ImageURL, vm.Title, vm.Year, genres, int.Parse(vm.ActorId), vm.Price, vm.Description, vm.TrailerURL); return(RedirectToAction("Movies", "ManageMovies")); }
public IActionResult Add(AddMovieViewModel addMovieViewModel) { if (ModelState.IsValid) { MovieGenre newMovieGenre = context.Genres.SingleOrDefault(c => c.ID == addMovieViewModel.GenreID); MovieStreamingService newMovieStreamingService = context.StreamingServices.SingleOrDefault(c => c.ID == addMovieViewModel.StreamingServiceID); Movie newMovie = new Movie { Title = addMovieViewModel.Name, StreamingService = newMovieStreamingService, Genre = newMovieGenre }; context.Movies.Add(newMovie); context.SaveChanges(); return(Redirect("/Movie")); } return(View(addMovieViewModel)); }
public ActionResult AddMovie() { var addMovieViewModel = new AddMovieViewModel(); addMovieViewModel.People = this.people .GetAll() .Select(p => new SelectListItem() { Text = p.FirstName + p.LastName, Value = p.Id.ToString() }) .ToList(); addMovieViewModel.Studios = this.studios .GetAll() .Select(s => new SelectListItem() { Text = s.Name, Value = s.Id.ToString() }) .ToList(); return this.PartialView("_AddMoviePartial", addMovieViewModel); }
public async Task <IActionResult> AddMovie(AddMovieViewModel model) { movie = new Movie(); var uploads = Path.Combine(_environment.WebRootPath, "Images/Posters"); foreach (var file in model.Files) { movie.Poster = file.FileName; if (file.Length > 0) { using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } } } movie.MovieID = model.MovieID; movie.MovieInfo = model.MovieInfo; movie.MovieSummary = model.MovieSummary; movie.MovieTitle = model.MovieTitle; movie.Stars = model.Stars; movie.Trailer = model.Trailer; movie.Writers = model.Writers; movie.Director = model.Director; int rowcount = movieCollection.CreateMovie(movie); if (rowcount == 1) { return(RedirectToAction("EditSuccessPage")); } else { return(RedirectToAction("FailPage")); } }
public ActionResult AddMovie() { var addMovieViewModel = new AddMovieViewModel(); addMovieViewModel.People = this.people .GetAll() .Select(p => new SelectListItem() { Text = p.FirstName + p.LastName, Value = p.Id.ToString() }) .ToList(); addMovieViewModel.Studios = this.studios .GetAll() .Select(s => new SelectListItem() { Text = s.Name, Value = s.Id.ToString() }) .ToList(); return(this.PartialView("_AddMoviePartial", addMovieViewModel)); }
public IActionResult AddMovieResult(AddMovieViewModel model) { var dbModel = new MovieDAL(); dbModel.MovieName = model.Movie.MovieName; dbModel.MovieGenre = model.Movie.MovieGenre; dbModel.UniqueId = Guid.NewGuid().ToString(); _movieDbContext.Movies.Add(dbModel); _movieDbContext.SaveChanges(); var movieList = _movieDbContext.Movies .Select(movieDal => new MovieVM() { MovieName = movieDal.MovieName, MovieGenre = movieDal.MovieGenre }) .ToList(); var viewModel = new AddMovieResultViewModel(); viewModel.Movies = movieList; return(View(viewModel)); }
public IActionResult Add([Bind("Title", "Description", "ReleaseDate", "Director", "Writer", "MovieStars", "files", "GenreId")] AddMovieViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } else if (ModelState.IsValid) { DateTime dateValue; if (!DateTime.TryParse(Convert.ToString(model.ReleaseDate), out dateValue)) { return(ReturnViewWithModelState(model, "ReleaseDate", "Please enter valid release date")); } else { if (model.ReleaseDate.Date < DateTime.Now) { return(ReturnViewWithModelState(model, "ReleaseDate", "Release date should be greater than or equal to today")); } } // Map fields using AutoMapper Movie movie = _mapper.Map <Movie>(model); if (model.files != null) { var file = model.files; if (file.Length > 0) { string[] segments = file.FileName.Split('.'); if (segments.Length == 1) { return(ReturnViewWithModelState(model, "files", "Please upload valid file")); } string fileExt = segments[1]; String[] extentionArr = new string[] { "jpg", "png", "jpeg", "gif", "bmp", "tif" }; if (Array.IndexOf(extentionArr, fileExt.ToLower()) < 0) { return(ReturnViewWithModelState(model, "files", "Please upload valid file (only images are allowed)")); } // Process uploaded image movie.Images = _commonFunction.ProcessUploadedImage(file, movie.Id, fileExt, segments); } } if (!String.IsNullOrEmpty(model.Director)) { movie.Directors = _commonFunction.GetMovieDirectors(model.Director, movie.Id); } if (!String.IsNullOrEmpty(model.Writer)) { movie.Writers = _commonFunction.GetMovieWriters(model.Writer, movie.Id); } if (!String.IsNullOrEmpty(model.MovieStars)) { movie.Stars = _commonFunction.GetMovieStars(model.MovieStars, movie.Id);; } // Add movie _movieService.AddMovie(movie); return(RedirectToAction("Index")); } } catch (Exception ex) { _commonFunction.LogException(ex); return(View(model)); } return(View(model)); }