Example #1
0
        public async Task AddMovie()
        {
            var movieDto = CreateMovies().Select(Map).Single(m => m.Id == 1L);
            var movie    = Map(movieDto);

            _mockingHelper.RepositoryMovie
            .Setup(_ => _.AddMovieAsync(movie))
            .ReturnsAsync(1L);

            _mockingHelper.RepositoryMovie.Setup(_ => _.GetActiveMovieByIdAsync(1L))
            .ReturnsAsync(movie);


            var result = await _movieService.AddMovieAsync(movieDto);

            result.Should().BeEquivalentTo(movieDto);
        }
Example #2
0
        public async Task <IActionResult> AddMovieAsync([FromBody] NewMovieDto dto)
        {
            var errors = GetErrorListFromModelState();

            if (errors.Any())
            {
                return(BadRequest(errors));
            }

            await _movieService.AddMovieAsync(dto);

            return(Ok());
        }
Example #3
0
        public async Task <IActionResult> Create(CreateMovieModel movieModel)
        {
            var errorMessage = String.Empty;

            if (!movieModel.ValidateCreateModel(out errorMessage))
            {
                ModelState.AddModelError(string.Empty, errorMessage);
                return(View());
            }
            await MovieService.AddMovieAsync(movieModel);

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> AddMovie([FromBody] AddMovieRequestViewModel addMovieModel, CancellationToken token = default)
        {
            AddMovieRequestModel requestModel = await addMovieModel.BuildAdapter().AdaptToTypeAsync <AddMovieRequestModel>();

            AddMovieResponseModel response = await _movieService.AddMovieAsync(requestModel, token);

            AddMovieResponseViewModel responseViewModel =
                await response.BuildAdapter().AdaptToTypeAsync <AddMovieResponseViewModel>();

            if (responseViewModel == null)
            {
                return(BadRequest());
            }

            return(Ok(responseViewModel));
        }
Example #5
0
        public async Task <IActionResult> AddMovieAsync(string movieData)
        {
            try
            {
                var movie = JsonConvert.DeserializeObject <SearchMovie>(movieData);

                if (movie == null)
                {
                    return(RedirectToAction("Index", "StatusCode", 500));
                }

                return(PartialView("~/Views/Main/Partials/_Result.cshtml",
                                   _mapper.Map <ResultViewModel>(await _service.AddMovieAsync(movie, GetCurrentSessionId()))));
            }
            catch
            {
                return(RedirectToAction("Index", "StatusCode", 500));
            }
        }
        public async Task <IActionResult> Create([FromBody] CreateMovieRequest request)
        {
            var movie = _movieService.CreateMovieFromRequest(request);

            var success = await _movieService.AddMovieAsync(movie);

            if (!success)
            {
                return(NotFound());
            }

            var baseUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
            var locationUri = baseUrl + "/" + ApiRoutes.Movies.Get.Replace("{Id}", movie.MovieGuid.ToString());

            var response = new MovieResponse {
                MovieId = movie.MovieGuid, Title = movie.Title
            };

            return(Created(locationUri, response));
        }
        public async Task <IActionResult> Add(AddMovieDTO addMovieDTO)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await _movieService.AddMovieAsync(addMovieDTO);

                    return(RedirectToAction("Add"));
                }

                return(View(addMovieDTO));
            }
            catch (FlowException ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);

                return(View(addMovieDTO));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
        private static void MovieCollector(IMovieService movieService, IPersonService personService,
                                           MyApiFilmsClient client, ConcurrentQueue queue)
        {
            while (queue.IncompleteMoviesWaiting() || queue.IncompletePersonsWaiting())
            {
                if (!queue.IncompleteMoviesWaiting())
                {
                    continue;
                }
                // ApiMovie is an alias for FilmIndustryNetwork.MyApiFilms.Entities.Movie
                // This is to distinguish between FilmIndustryNetwork.MyApiFilms.Entities.Movie
                // and FilmIndustryNetwork.Entities.Movie
                ApiMovie apiMovie;
                var      title = queue.PopIncompleteMovie();

                if (title == "---")
                {
                    continue;
                }

                try
                {
                    apiMovie =
                        client.GetDataAsObject <MovieResponse>(title, DataSetType.Movie)?.Data?.Movies?.FirstOrDefault();

                    if (apiMovie == null)
                    {
                        throw new Exception();
                    }

                    if (apiMovie.Type.Contains("TV"))
                    {
                        continue;
                    }
                }
                catch (MyApiFilmsTimeoutException e)
                {
                    // TODO: setup logging
                    FillQueueFromList(movieService, null, new [] { title }, queue, 0);
                    continue;
                }
                catch (NoMyApiFilmsResponseException e)
                {
                    // TODO: setup logging
                    continue;
                }
                catch (Exception)
                {
                    // TODO: setup logging
                    FillQueueFromList(movieService, null, new[] { title }, queue, 0);
                    continue;
                }

                var newMovie = new Movie
                {
                    Countries        = apiMovie.Countries,
                    FilmingLocations = apiMovie.FilmingLocations,
                    Genres           = apiMovie.Genres,
                    Id             = apiMovie.IdIMDB,
                    Languages      = apiMovie.Languages,
                    Plot           = apiMovie.Plot,
                    NeedsApiLookup = false,
                    Rated          = apiMovie.Rated,
                    Rating         = apiMovie.Rating,
                    Title          = apiMovie.Title,
                    Year           = apiMovie.Year
                };

                FillQueueFromList(null, personService, apiMovie.Actors.Select(x => x.ActorName).ToList(), queue, 1);
                FillQueueFromList(null, personService, apiMovie.Directors.Select(x => x.Name).ToList(), queue, 1);
                FillQueueFromList(null, personService, apiMovie.Writers.Select(x => x.Name).ToList(), queue, 1);

                AddRelationshipsToQueue(new[] { apiMovie.IdIMDB }, apiMovie.Actors.Select(x => x.ActorName).ToList(), queue,
                                        RelationTypes.ActedIn);
                AddRelationshipsToQueue(new[] { apiMovie.IdIMDB }, apiMovie.Directors.Select(x => x.Name).ToList(), queue,
                                        RelationTypes.DirectorFor);
                AddRelationshipsToQueue(new[] { apiMovie.IdIMDB }, apiMovie.Writers.Select(x => x.Name).ToList(), queue,
                                        RelationTypes.WriterOf);

                var existingMovie = movieService.GetMovieByIdAsync(newMovie.Id).Result;

                if (existingMovie != null)
                {
                    continue;
                }

                movieService.AddMovieAsync(newMovie).Wait();
            }
        }
 public async Task <MovieDataDto> AddMovieAsync(MovieDataDto movieData)
 {
     return(await _movieService.AddMovieAsync(movieData));
 }
        private static void MovieCollector(IMovieService movieService, IPersonService personService, 
            MyApiFilmsClient client, ConcurrentQueue queue)
        {
            while (queue.IncompleteMoviesWaiting() || queue.IncompletePersonsWaiting())
            {
                if (!queue.IncompleteMoviesWaiting()) continue;
                // ApiMovie is an alias for FilmIndustryNetwork.MyApiFilms.Entities.Movie
                // This is to distinguish between FilmIndustryNetwork.MyApiFilms.Entities.Movie
                // and FilmIndustryNetwork.Entities.Movie
                ApiMovie apiMovie;
                var title = queue.PopIncompleteMovie();

                if (title == "---") continue;

                try
                {
                    apiMovie =
                        client.GetDataAsObject<MovieResponse>(title, DataSetType.Movie)?.Data?.Movies?.FirstOrDefault();

                    if (apiMovie == null) throw new Exception();

                    if (apiMovie.Type.Contains("TV")) continue;
                }
                catch (MyApiFilmsTimeoutException e)
                {
                    // TODO: setup logging
                    FillQueueFromList(movieService, null, new [] {title}, queue, 0);
                    continue;
                }
                catch (NoMyApiFilmsResponseException e)
                {
                    // TODO: setup logging
                    continue;
                }
                catch (Exception)
                {
                    // TODO: setup logging
                    FillQueueFromList(movieService, null, new[] { title }, queue, 0);
                    continue;
                }

                var newMovie = new Movie
                {
                    Countries = apiMovie.Countries,
                    FilmingLocations = apiMovie.FilmingLocations,
                    Genres = apiMovie.Genres,
                    Id = apiMovie.IdIMDB,
                    Languages = apiMovie.Languages,
                    Plot = apiMovie.Plot,
                    NeedsApiLookup = false,
                    Rated = apiMovie.Rated,
                    Rating = apiMovie.Rating,
                    Title = apiMovie.Title,
                    Year = apiMovie.Year
                };

                FillQueueFromList(null, personService, apiMovie.Actors.Select(x => x.ActorName).ToList(), queue, 1);
                FillQueueFromList(null, personService, apiMovie.Directors.Select(x => x.Name).ToList(), queue, 1);
                FillQueueFromList(null, personService, apiMovie.Writers.Select(x => x.Name).ToList(), queue, 1);

                AddRelationshipsToQueue(new[] {apiMovie.IdIMDB}, apiMovie.Actors.Select(x => x.ActorName).ToList(), queue,
                    RelationTypes.ActedIn);
                AddRelationshipsToQueue(new[] {apiMovie.IdIMDB}, apiMovie.Directors.Select(x => x.Name).ToList(), queue,
                    RelationTypes.DirectorFor);
                AddRelationshipsToQueue(new[] {apiMovie.IdIMDB}, apiMovie.Writers.Select(x => x.Name).ToList(), queue,
                    RelationTypes.WriterOf);

                var existingMovie = movieService.GetMovieByIdAsync(newMovie.Id).Result;

                if (existingMovie != null) continue;

                movieService.AddMovieAsync(newMovie).Wait();
            }
        }