Exemple #1
0
        public static void ImportMovie(MovieDTO movieDto)
        {
            string movieName = movieDto.Name;

            InputDataValidator.ValidateStringMaxLength(movieName, Constants.MaxMovieNameLength);

            float?rating = movieDto.Rating;

            InputDataValidator.ValidateFloatInRange(rating, Constants.MinRatingValue, Constants.MaxRatingValue);

            int releaseYear = movieDto.ReleaseYear;

            MovieValidator.ValidateMovieDoesNotExist(movieName, releaseYear);

            List <string> categories = movieDto.Categories.Select(c => c.Name).ToList();

            CategoryValidator.CheckCategoriesExist(categories);

            string         directorName   = movieDto.DirectorName;
            int            length         = movieDto.Length;
            AgeRestriction ageRestriction = (AgeRestriction)Enum.Parse(typeof(AgeRestriction), movieDto.AgeRestriction);
            string         synopsis       = movieDto.Synopsis;
            string         releaseCountry = movieDto.ReleaseCountry;

            byte[] image = movieDto.Image;


            MovieService.AddMovie(movieName, rating, length, directorName, releaseYear, ageRestriction, synopsis,
                                  releaseCountry, image);
            MovieImportService.AddCategoriesToMovie(movieName, releaseYear, categories);

            Console.WriteLine(string.Format(Constants.ImportSuccessMessages.MoviesAddedSuccess, movieName));
        }
Exemple #2
0
 public MovieImportService()
 {
     this.categoryService   = new CategoryService();
     this.categoryValidator = new CategoryValidator(categoryService);
     this.movieService      = new MovieService();
     this.movieValidator    = new MovieValidator(movieService);
 }
 public ProfilePage()
 {
     loginHandler   = new LoginHandler();
     movieValidator = new MovieValidator();
     clientHandler  = new ClientHandler();
     InitializeComponent();
 }
Exemple #4
0
 public ActorImportService()
 {
     this.actorService   = new ActorService();
     this.actorValidator = new ActorValidator(actorService);
     this.movieService   = new MovieService();
     this.movieValidator = new MovieValidator(movieService);
 }
        public ActionResult getMovie(string movieId)
        {
            MovieDTO movieDto;

            if (!MovieValidator.ValidateMovieId(movieId))
            {
                return(BadRequest("Please enter a valid movieId"));
            }

            Movie movie = GetMovieFromCache(movieId);

            if (movie != null)
            {
                movieDto = movie.Adapt <MovieDTO>();
            }
            else
            {
                var doc = getWebsiteHtmlDocument(movieId);

                try
                {
                    movieDto = CreateMovieDto(movieId, doc);
                }
                catch (Exception e)
                {
                    return(NotFound(e.Message));
                }
            }

            return(Ok(movieDto));
        }
Exemple #6
0
        public static void ImportScreening(ScreeeningDto screeningDto)
        {
            byte auditoriumNumber = screeningDto.AuditoriumNumber;

            string cinemaTown = screeningDto.CinemaTown;

            TownValidator.CheckTownExisting(cinemaTown);

            int    townId     = TownService.GetTownId(cinemaTown);
            string cinemaName = screeningDto.CinemaName;

            CinemaValidator.CheckCinemaExisting(cinemaName, townId);

            int cinemaId = CinemaService.GetCinemaId(cinemaName, townId);

            AuditoriumValidator.CheckAuditoriumExists(auditoriumNumber, cinemaId, cinemaName);

            string movieName        = screeningDto.MovieName;
            int    movieReleaseYear = screeningDto.MovieReleaseYear;

            MovieValidator.CheckMovieExists(movieName, movieReleaseYear);

            int      auditoriumId = AuditoriumService.GetAuditoriumId(auditoriumNumber, cinemaId);
            DateTime date         = screeningDto.Date;

            ScreeningValidator.ValidateScreeningDoesntExist(auditoriumId, date);

            int movieId = MovieService.GetMovieId(movieName, movieReleaseYear);

            ScreeningService.AddScreening(auditoriumId, movieId, date);

            Console.WriteLine(string.Format(Constants.ImportSuccessMessages.ScreeningAddedSuccess, auditoriumNumber, cinemaName));
        }
        public async Task <ActionResult> Details(string movieId)
        {
            MovieDetailsDTO movieDetailsDto = null;
            Movie           movie           = GetMovieFromCache(movieId);

            if (!MovieValidator.ValidateMovieId(movieId))
            {
                return(BadRequest("Please enter a valid movieId"));
            }

            if (movie == null)
            {
                var doc = getWebsiteHtmlDocument(movieId);

                movieDetailsDto = CreateMovieDetailsDto(movieId, doc);

                movie = movieDetailsDto.Adapt <Movie>();

                await AddToBothCache(movie);
            }
            else
            {
                if (movie.Source == "Database")
                {
                    AddToConcurrentCache(movie);
                }

                movieDetailsDto = movie.Adapt <MovieDetailsDTO>();
            }

            return(Ok(movieDetailsDto));
        }
Exemple #8
0
 public void UpdateMovie(int movieId, [FromBody] MovieViewModel movieVm)
 {
     if (MovieValidator.IsValid(movieVm))
     {
         _moviesHandler.Update(movieId, movieVm);
     }
     else
     {
         Request.HttpContext.Response.StatusCode = 400;
     }
 }
Exemple #9
0
 public void AddMovie([FromBody] MovieViewModel movieVm)
 {
     if (MovieValidator.IsValid(movieVm))
     {
         _moviesHandler.Add(movieVm);
     }
     else
     {
         Request.HttpContext.Response.StatusCode = 400;
     }
 }
Exemple #10
0
 private void SaveMovie()
 {
     if (Cache.Movie.Id != 0)
     {
         MovieValidator.MovieUpdateValidation(Cache.Movie.Id, Cache.Movie.Name, Cache.Movie.Length);
     }
     else
     {
         MovieValidator.MovieAddValidation(Cache.Movie.Name, Cache.Movie.Length);
     }
 }
 public ScreeningImportService()
 {
     this.auditoriumService   = new AuditoriumService();
     this.cinemaService       = new CinemaService();
     this.auditoriumValidator = new AuditoriumValidator(auditoriumService);
     this.cinemaValidator     = new CinemaValidator(cinemaService);
     this.movieService        = new MovieService();
     this.movieValidator      = new MovieValidator(movieService);
     this.townService         = new TownService();
     this.townValidator       = new TownValidator(townService);
     this.screeningService    = new ScreeningService();
     this.screeningValidator  = new ScreeningValidator(screeningService);
 }
Exemple #12
0
        public void Using_custom_validator()
        {
            var model = new Movie
            {
                Id          = 1,
                Title       = "Dr. No",
                ReleaseYear = 1963
            };

            var validator = new MovieValidator(model);
            var issues    = validator.Validate();

            Assert.False(issues.HasIssues);
        }
Exemple #13
0
        public void Setup()
        {
            _validator = new MovieValidator();
            //Criando options do contexto que configura a base de dados para InMemory
            //Não é boa praticar usar Mockar a classe EF core, que não é Mock friendly
            var dbContextOptions =
                new DbContextOptionsBuilder <MovieContext>().UseInMemoryDatabase(databaseName: "TestDb");

            //Iniciando o contexto para teste com banco de dados in_memory
            _context_for_test_in_memory = new MovieContext(dbContextOptions.Options);

            //Iniciando o reposório injetando a dependencia do contexto com data base in memory.
            _movieRepository = new MovieRepository(_context_for_test_in_memory);
        }
 private void SaveSeance()
 {
     if (Cache.Seance.Id != 0)
     {
         SeanceValidator.SeanceUpdateValidation(
             Cache.Seance.Id,
             MovieValidator.GetMovieByName(Cache.Seance.Movie.Name).Id,
             HallValidator.GetHallByName(Cache.Seance.Hall.Name).Id,
             Cache.Seance.Time
             );
     }
     else
     {
         SeanceValidator.SeanceAddValidation(
             MovieValidator.GetMovieByName(Cache.Seance.Movie.Name).Id,
             HallValidator.GetHallByName(Cache.Seance.Hall.Name).Id,
             Cache.Seance.Time
             );
     }
 }
        public static void ImportActor(ActorDTO actorDto)
        {
            string actorName = actorDto.Name;

            InputDataValidator.ValidateStringMaxLength(actorName, Constants.MaxActorNameLength);
            ActorValidator.ValidateActorDoesntExist(actorName);

            float?actorRating = actorDto.Rating;

            InputDataValidator.ValidateFloatInRange(actorRating, Constants.MinRatingValue, Constants.MaxRatingValue);

            List <ActorMovieDto> movies = actorDto.Movies;

            MovieValidator.CheckMoviesExist(movies);

            ActorService.AddActor(actorName, actorRating);
            ActorImportService.AddMoviesToActor(actorName, movies);

            Console.WriteLine(string.Format(Constants.ImportSuccessMessages.ActorAddedSuccess, actorName));
        }
Exemple #16
0
        public void TestValidateMovie()
        {
            var movieValidator = new MovieValidator();

            Assert.IsFalse(movieValidator.ValidateMovie("123124;';'", "Action", "Portman"));
        }
Exemple #17
0
        public override ValidationResult Validate()
        {
            var movieValidator = new MovieValidator();

            return(movieValidator.Validate(this));
        }
Exemple #18
0
 public MoviePage()
 {
     adminMovieHandler = new AdminMovieHandler();
     movieValidator    = new MovieValidator();
     InitializeComponent();
 }
 public EditMovieCommand(MFGContext context, IMapper mapper, MovieValidator validator)
 {
     _context   = context;
     _mapper    = mapper;
     _validator = validator;
 }
 private string[] GetMoviesArray()
 {
     return(MovieValidator.GetAllMovies().Select(x => x.Name).ToArray());
 }
Exemple #21
0
 public HomePageClient()
 {
     InitializeComponent();
     clientHandler  = new ClientHandler();
     movieValidator = new MovieValidator();
 }
Exemple #22
0
        public void TestValidateMovieActors()
        {
            var movieValidator = new MovieValidator();

            Assert.IsFalse(movieValidator.ValidateMovieTitleGenreOrActors("123124;';'"));
        }
 public EfUpdateMovie(MovieReviewContext context, IMapper mapper, MovieValidator validator)
 {
     this.context   = context;
     this.mapper    = mapper;
     this.validator = validator;
 }