public void AddMovie_WithFilledMovie_ReturnAddedMovie() { var movie = new Movie() { Title = "MyMovie" }; var result = movieService.AddMovie(movie); result.Should().BeOfType <ObjectResult>().Which.StatusCode.Should().Be(201); result.Should().BeOfType <ObjectResult>().Which.Value.Should().BeOfType <Movie>().Which.MovieId.Should().BePositive(); }
public async Task <IActionResult> CreateMovie([FromBody] MovieCreateDto movieCreateDto) { if (movieCreateDto == null) { return(BadRequest()); } var movieExist = await _movieService.MovieExistById(movieCreateDto.ImdbId); if (movieExist) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } var movie = _mapper.Map <MovieCreateDto, Movie>(movieCreateDto); var success = await _movieService.AddMovie(movie); if (!success) { // Throw code 500 instead of 4xx when saving changes failed because it is a server side issue throw new Exception($"Failed to save the user to the database with the id {movie.Id}"); } var movieToReturn = _mapper.Map <Movie, MovieGetDto>(movie); var routeValue = new { id = movie.Id }; return(CreatedAtRoute(GetMovieByIdRoute, routeValue, movieToReturn)); }
public ActionResult PostMovie([FromBody] Movie movie) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { if (_service.MovieExists(movie.Id)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { _service.AddMovie(movie); } } catch (Exception) { return(BadRequest("Please check the movie details that you have entered.")); } return(CreatedAtAction("GetMovie", new { id = movie.Id }, movie)); }
public ActionResult CreateOrUpdate( [Bind(Include = "Id,Title,PremiereDate,Desctiption,CountryId,DirectorId,ImdbId,TrailerLink")] MovieViewModel movieViewModel, HttpPostedFileBase file, string[] selectedGenres, string[] selectedActors) { bool isCreate = false; if (ModelState.IsValid) { if (movieViewModel.Id == new Guid()) { movieViewModel.Id = Guid.NewGuid(); isCreate = true; } SaveImage(movieViewModel, file); CreateOfUpdateActorsInMovie(selectedActors, movieViewModel); CreateOfUpdateGenresOfMovie(selectedGenres, movieViewModel); AddDirector(movieViewModel); movieViewModel.TrailerLink += "&autoplay=1"; Movie movie = Mapper.Map <MovieViewModel, Movie>(movieViewModel); if (isCreate) { _movieService.AddMovie(movie); } else { _movieService.Edit(movie); } return(RedirectToAction("Index")); } return(View(movieViewModel)); }
public IActionResult Create(MovieViewModel movieViewModel) { var movie = new Movie(); if (ModelState.IsValid) { movie.CategoryID = movieViewModel.CategoryID; movie.CategoryName = movieViewModel.CategoryName; movie.Copies = movieViewModel.Copies; movie.Country = movieViewModel.Country; movie.Description = movieViewModel.Description; movie.Language = movieViewModel.Language; movie.Price = movieViewModel.Price; movie.Shipping = movieViewModel.Shipping; movie.Title = movieViewModel.Title; movie.YearOfRelease = movieViewModel.YearOfRelease; movie.UserId = movieViewModel.UserId; movie.DirectorID = movieViewModel.DirectorID; movie.DirectorName = movieViewModel.DirectorName; movie.PhotoURL = movieViewModel.PhotoURL; _movieService.AddMovie(movie); _logger.LogInformation(LoggerMessageDisplay.MovieCreated); return(RedirectToAction(nameof(Index))); } _logger.LogError(LoggerMessageDisplay.MovieNotCreatedModelStateInvalid); return(View(movie)); }
public IActionResult Create( [FromBody] MovieInputModel inputModel, [FromHeader(Name = "Accept")] string acceptHeader) { if (inputModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(Unprocessable(ModelState)); } var model = ToDomainModel(inputModel); service.AddMovie(model); if (string.Equals(acceptHeader, "application/vnd.fiver.hateoas+json")) { var outputModel = ToOutputModel_Links(model); return(CreatedAtRoute("GetMovie", new { id = outputModel.Value.Id }, outputModel)); } else { var outputModel = ToOutputModel_Default(model); return(CreatedAtRoute("GetMovie", new { id = outputModel.Id }, outputModel)); } }
public IActionResult Save(int id, MovieViewModel viewModel) { if (viewModel == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(View("CreateOrEdit", viewModel)); } var model = ToDomainModel(viewModel); if (viewModel.IsNew) { service.AddMovie(model); } else { service.UpdateMovie(model); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Create(Movie movie) { try { string path = "/Images/" + movie.Image.FileName; using (var fileStream = new FileStream(_hostingEnvironment.WebRootPath + path, FileMode.Create)) { await _movieService.CopyImage(fileStream, movie); } if (ModelState.IsValid) { var movieEntity = _mapper.Map <MovieEntity>(movie); movieEntity.FileName = movie.Image.FileName; movieEntity.UserId = _userManager.GetUserId(User); await _movieService.AddMovie(movieEntity); return(RedirectToAction("Index")); } } catch (Exception ex) { return(View(ex.Message)); } return(View(movie)); }
public IActionResult OnPost() { _ms.AddMovie(new Models.Movies { Name = MVM.Name, gender = MVM.gender, release = MVM.release }); return(RedirectToPage("./Index")); }
public ActionResult AddMovie(MovieViewModel model) { Movie movie = new Movie(_movieService.GetAllMovies().Count(), model.Title, "", model.ReleaseDate, model.Description); _movieService.AddMovie(movie); return(RedirectToAction("Index")); }
public void Execute(NetImportSyncCommand message) { //if there are no lists that are enabled for automatic import then dont do anything if ((_netImportFactory.GetAvailableProviders()).Where(a => ((NetImportDefinition)a.Definition).EnableAuto).Empty()) { _logger.Info("No lists are enabled for auto-import."); return; } var listedMovies = Fetch(0, true); CleanLibrary(listedMovies); listedMovies = listedMovies.Where(x => !_movieService.MovieExists(x)).ToList(); if (listedMovies.Any()) { _logger.Info($"Found {listedMovies.Count()} movies on your auto enabled lists not in your library"); } var importExclusions = new List <string>(); //var downloadedCount = 0; foreach (var movie in listedMovies) { var mapped = _movieSearch.MapMovieToTmdbMovie(movie); if (mapped != null && !_exclusionService.IsMovieExcluded(mapped.TmdbId)) { //List<DownloadDecision> decisions; mapped.AddOptions = new AddMovieOptions { SearchForMovie = true }; _movieService.AddMovie(mapped); //// Search for movie //try //{ // decisions = _nzbSearchService.MovieSearch(mapped.Id, false); //} //catch (Exception ex) //{ // _logger.Error(ex, $"Unable to search in list for movie {mapped.Id}"); // continue; //} //var processed = _processDownloadDecisions.ProcessDecisions(decisions); //downloadedCount += processed.Grabbed.Count; } else { if (mapped != null) { _logger.Info($"{mapped.Title} ({mapped.TitleSlug}) will not be added since it was found on the exclusions list"); } } } //_logger.ProgressInfo("Movie search completed. {0} reports downloaded.", downloadedCount); }
public IActionResult Post([FromBody] Movie movie) { if (movieService.AddMovie(movie)) { return(Json(new{ message = "Success" })); } return(Json(new{ message = "Failure" })); }
public IActionResult Create([Bind("Title,ReleaseDate,Genre,Price")] InputMovieViewModel inputModel) { if (ModelState.IsValid) { _service.AddMovie(_mapper.Map <MovieDto>(inputModel)); return(RedirectToAction(nameof(Index))); } return(View(inputModel)); }
public IActionResult Create([Bind("Id,Title,Price")] Movie movie) { if (ModelState.IsValid) { _service.AddMovie(movie); return(RedirectToAction(nameof(Index))); } return(View(movie)); }
public ActionResult Create(MovieViewModel movie) { if (ModelState.IsValid) { movieService.AddMovie(movie.ToBllEntity()); return(RedirectToAction("Index")); } return(View(movie)); }
private Movie AddMovie() { Movie movie = new Movie { Title = "Titulo Filme" }; return(_movieService.AddMovie(movie).Result); }
public ActionResult Create([Bind(Include = "Id,Title,ReleaseDate,Genre,Price,Rating")] Movie movie) { if (ModelState.IsValid) { _service.AddMovie(movie); return(RedirectToAction("Index")); } return(View(movie)); }
public IActionResult AddMovie([FromBody] MovieDto movieDto) { MovieDto movieDtoObj = _movieService.AddMovie(movieDto); if (movieDtoObj == null) { return(BadRequest("Failed to add movie!")); } return(Ok(movieDtoObj)); }
public IHttpActionResult AddMovie([FromBody] Movie movie) { if (!ModelState.IsValid) { return(BadRequest()); } _movieWCFService.AddMovie(movie); return(Ok(movie)); }
public async Task <ActionResult> AddMovieAsync(Movie movie) { if (movie == null) { return(BadRequest(movie)); } var addMovieResult = await _movieService.AddMovie(movie); return(Ok(addMovieResult)); }
public async Task <ActionResult <ExtendedMovieDTO> > AddMovie(ExtendedMovieDTO movie) { try { return(new OkObjectResult(await _movieService.AddMovie(movie))); } catch { return(new StatusCodeResult(500)); } }
public async Task <IActionResult> Post([FromBody] Movie movie) { var addedMovie = await _movieService.AddMovie(movie); if (movie == null) { return(NotFound()); } return(Ok(movie)); }
public IActionResult AddMovie([FromForm] MovieSaveDto movie) { var result = _movieService.AddMovie(movie); if (!result.Success) { return(BadRequest(result.Message)); } return(Ok(result.Movie)); }
public async Task <ActionResult <MoviesDTO> > AddMovie(MoviesDTO movie) { try { return(new OkObjectResult(await _movieService.AddMovie(movie))); } catch (System.Exception ex) { return(new StatusCodeResult(500)); } }
public Movie AddMovie(Movie newMovie) { Ensure.That(newMovie, () => newMovie).IsNotNull(); newMovie = AddSkyhookData(newMovie); newMovie = SetPropertiesAndValidate(newMovie); _logger.Info("Adding Movie {0} Path: [{1}]", newMovie, newMovie.Path); _movieService.AddMovie(newMovie); return(newMovie); }
public IActionResult Post([FromBody] MovieModel model) { try { model.UserId = GetAuthorizedUserId(); _movieService.AddMovie(model); return(Ok("Successfully added movie!")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <ActionResult <MovieViewModel> > AddMovie(Movie1ViewModel movie1ViewModel) { if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } MovieViewModel movieViewModel = _mapper.Map <MovieViewModel>( await _movieService.AddMovie(_mapper.Map <Movie>(movie1ViewModel))); return(CustomResponse(movieViewModel)); }
public async Task <ActionResult> CreateNewMovieWithHisTags([FromBody] CreateMovieModel movieModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } MovieDomainModel domainModel = new MovieDomainModel { Current = movieModel.Current, Rating = movieModel.Rating, Title = movieModel.Title, Year = movieModel.Year }; MovieCreateTagDomainModel movieCreateTagDomainModel = new MovieCreateTagDomainModel { Duration = movieModel.Duration, tagsForMovieToAdd = movieModel.listOfTags }; MovieDomainModel createMovie; try { createMovie = await _movieService.AddMovie(domainModel, movieCreateTagDomainModel); } catch (DbUpdateException e) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = e.InnerException.Message ?? e.Message, StatusCode = System.Net.HttpStatusCode.BadRequest }; return(BadRequest(errorResponse)); } if (createMovie == null) { ErrorResponseModel errorResponse = new ErrorResponseModel { ErrorMessage = Messages.MOVIE_CREATION_ERROR, StatusCode = System.Net.HttpStatusCode.InternalServerError }; return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError, errorResponse)); } return(Created("movies//" + createMovie.Id, createMovie)); }
public void TestAddMovie() { Movie movie = new Movie { Title = "Titulo Filme" }; movie = _service.AddMovie(movie).Result; movie = _service.GetMovie(movie.Id).Result; Assert.AreEqual(1, movie.Id, "Id"); Assert.AreEqual("Titulo Filme", movie.Title, "Título"); Assert.AreEqual(MovieStatus.Available, movie.Status, "Status"); }
public ActionResult <MovieDTO> Post(MovieDTO movieDTO) { var movie = new Movie { Title = movieDTO.Title, Language = movieDTO.Language, Duration = movieDTO.Duration, MovieId = movieDTO.MovieId, ReleaseYear = movieDTO.ReleaseYear }; var newMovie = movieService.AddMovie(movie); return(CreatedAtAction(nameof(GetMovieById), new { movieId = movie.MovieId }, movieDTO)); }