示例#1
0
        public async Task <bool> Handle(AddMovieCommand message, CancellationToken cancellationToken)
        {
            if (!CastOfMovieIsValid(message))
            {
                return(false);
            }

            var movie           = MovieFactory.Create(message.Genre, message.Title);
            var castOfMovieList = new List <CastOfMovie>();

            foreach (var castId in message.CastIds)
            {
                var castOfMovieModel = CastOfMovieFactory.Create(movie.Id, castId);
                if (!castOfMovieModel.IsValid())
                {
                    NotifyValidationErrors(castOfMovieModel.ValidationResult);
                    return(false);
                }

                castOfMovieList.Add(castOfMovieModel);
            }

            movie.AddCastOfMovie(castOfMovieList);
            if (!movie.IsValid())
            {
                NotifyValidationErrors(movie.ValidationResult);
                return(false);
            }

            _movieRepository.Add(movie);

            return(await Task.FromResult(Commit()));
        }
示例#2
0
        public async Task <bool> Handle(AddMeanCommand message, CancellationToken cancellationToken)
        {
            var ratingOfMovie = _movieRepository.GetRatingOfMoviesByFilters(m => m.MovieId == message.MovieId,
                                                                            include => include.Movie).ToList();

            if (!ratingOfMovie.Any())
            {
                return(false);
            }

            var mean  = ratingOfMovie.Select(x => x.Rate).Average();
            var movie = ratingOfMovie.Select(x => x.Movie).FirstOrDefault();

            if (movie == null)
            {
                return(false);
            }

            var movieToUpdate = MovieFactory.Create(movie.Genre, movie.Title, movie.Id);

            movieToUpdate.AddMean((float)mean);

            _movieRepository.Update(movieToUpdate);

            return(await Task.FromResult(Commit()));
        }
示例#3
0
        public async Task Add(Guid movieId, CreateMovieRequest request)
        {
            Movie movie = MovieFactory.Create(movieId, request.Title);

            _ctx.Add(movie);
            await _ctx.SaveChangesAsync();
        }
示例#4
0
        public void Create_WhenCreated_SetsProperties()
        {
            const int    id           = 100;
            const string language     = "some movie language";
            const string location     = "some movie location";
            const string title        = "some movie title";
            const string plot         = "some interesting thriller plot!";
            const string poster       = "some interesting poster link";
            var          soundEffects = new string[] {
                "some soundEffects", "next soundEffects"
            };
            var stills = new string[] {
                "some stills", "next stills"
            };
            const string imdbRating  = "12345";
            const string imbdId      = "78990";
            const string listingType = "1234";

            var movieResponse = new MovieResponse()
            {
                Id           = id,
                Language     = language,
                Location     = location,
                Title        = title,
                Plot         = plot,
                Poster       = poster,
                SoundEffects = soundEffects,
                Stills       = stills,
                ImdbRating   = imdbRating,
                ImdbId       = imbdId,
                ListingType  = listingType
            };
            var result = _movieFactoryTests.Create(movieResponse);

            Assert.Equal(id, result.Id);
            Assert.Equal(language, result.Language);
            Assert.Equal(location, result.Location);
            Assert.Equal(title, result.Title);
            Assert.Equal(plot, result.Plot);
            Assert.Equal(poster, result.Poster);
            Assert.Same(soundEffects, result.SoundEffects);
            Assert.Equal(imbdRating, result.ImbdRating);
            Assert.Equal(imbdId, result.ImdbId);
            Assert.Equal(listingType, result.ListingType);
        }
示例#5
0
        public JsonResult Ajax([DataSourceRequest] DataSourceRequest request)
        {
            var movies = MovieFactory.Create();

            return(Json(movies.ToDataSourceResult(request)));
        }
示例#6
0
        public ActionResult Index()
        {
            var movies = MovieFactory.Create();

            return(View(movies));
        }
示例#7
0
 public void Execute()
 {
     var name      = _movieConsole.GetName();
     int priceCode = _movieConsole.GetPriceCode();
     var movie     = _movieFactory.Create(name, priceCode);
 }