Beispiel #1
0
 private static void AssertMovieInfosEquals(MovieInfos a, MovieInfos b)
 {
     Assert.AreEqual(a.GuessedTitle, b.GuessedTitle, "Title of " + a.Path);
     Assert.AreEqual(a.GuessedYear, b.GuessedYear, "Year of " + a.Path);
     Assert.AreEqual(a.ShouldBeIgnored, b.ShouldBeIgnored, "ShouldBeIgnored of " + a.Path);
     Assert.AreEqual(a.Path, b.Path, "Path of " + a.Path);
     Assert.AreEqual(a.SeamsDuplicated, b.SeamsDuplicated, "SeamsDuplicated of " + a.Path);
 }
Beispiel #2
0
        public async Task <MovieViewModel> GetMovieInfo(string id)
        {
            var result = await MovieInfos.Include(i => i.Genres).ThenInclude(i => i.Genre).FirstOrDefaultAsync(i => i.Id == id);

            if (result == null)
            {
                return(null);
            }
            return(_mapper.Map <MovieViewModel>(result));
        }
Beispiel #3
0
        public async Task <List <MovieViewModel> > GetMovieInfos(MovieRequest request)
        {
            var movies = await Task.Run(() => {
                return(_cache.Use(RequestKey(request), () =>
                                  MovieInfos.Include(i => i.Genres).ThenInclude(i => i.Genre)
                                  .Where(movie => !RequestIsNotEmpty(request) ||
                                         !string.IsNullOrEmpty(request.Actors) && movie.Actors.Contains(request.Actors, StringComparison.InvariantCultureIgnoreCase) ||
                                         !string.IsNullOrEmpty(request.Country) && movie.Country.Equals(request.Country, StringComparison.InvariantCultureIgnoreCase) ||
                                         !string.IsNullOrEmpty(request.Description) &&
                                         movie.Description.Contains(request.Description, StringComparison.InvariantCultureIgnoreCase) ||
                                         !string.IsNullOrEmpty(request.Genre) &&
                                         movie.Genres.Exists(g =>
                                                             movie.Genres.Any(gn => gn.Genre.Name.Equals(request.Genre, StringComparison.InvariantCultureIgnoreCase))) ||
                                         !string.IsNullOrEmpty(request.Title) && movie.Title.Contains(request.Title, StringComparison.InvariantCultureIgnoreCase) ||
                                         request.Year > 0 && movie.Released.Year == request.Year
                                         ).ToListAsync()));
            });

            switch (request.SortBy)
            {
            case SortOptions.ByCountry:
                movies = movies.OrderBy(o => o.Country).Skip((request.Page - 1) * request.PageSize).Take(request.PageSize).ToList();
                break;

            case SortOptions.ByDate:
                movies = movies.OrderBy(o => o.Released).Skip((request.Page - 1) * request.PageSize).Take(request.PageSize).ToList();
                break;

            case SortOptions.ByTitle:
                movies = movies.OrderBy(o => o.Title).Skip((request.Page - 1) * request.PageSize).Take(request.PageSize).ToList();
                break;

            case SortOptions.ByCountryDesc:
                movies = movies.OrderByDescending(o => o.Country).Skip((request.Page - 1) * request.PageSize).Take(request.PageSize).ToList();
                break;

            case SortOptions.ByDateDesc:
                movies = movies.OrderByDescending(o => o.Released).Skip((request.Page - 1) * request.PageSize).Take(request.PageSize).ToList();
                break;

            case SortOptions.ByTitleDesc:
                movies = movies.OrderByDescending(o => o.Title).Skip((request.Page - 1) * request.PageSize).Take(request.PageSize).ToList();
                break;

            default:
                movies = movies.Skip((request.Page - 1) * request.PageSize).Take(request.PageSize).ToList();
                break;
            }

            return(_mapper.Map <List <MovieViewModel> >(movies));
        }
Beispiel #4
0
 static void WriteResult(MovieInfos m, bool good)
 {
     using (var w = new StreamWriter("result.txt", true))
     {
         //MovieInfos(String title, int? year, String path, bool seamsDuplicated, bool ignore)
         w.WriteLine("new TestResult({5}, new MovieInfos(\"{0}\", {1}, @\"{2}\", {3}, {4})),",
                     m.GuessedTitle,
                     m.GuessedYear == null ? "null" : m.GuessedYear.ToString(),
                     m.Path,
                     m.SeamsDuplicated ? "true" : "false",
                     m.ShouldBeIgnored ? "true" : "false",
                     good ? "true" : "false");
     }
 }
        public async Task AddCartItem(int customerId, CartViewModel vm)
        {
            var item = await CartItems.Include(i => i.Movie).FirstOrDefaultAsync(i => i.Movie.Id == vm.MovieId);

            var movie = await MovieInfos.FirstOrDefaultAsync(i => i.Id == vm.MovieId);

            if (item == null && movie != null)
            {
                await CartItems.AddAsync(new CartItem
                {
                    CustomerId = customerId,
                    Movie      = movie,
                    Paid       = false,
                    Price      = vm.Price,
                    ProvidedBy = vm.ProvidedBy
                });
                await SaveChangesAsync();
            }
        }
Beispiel #6
0
 public TestResult(bool ok, MovieInfos movie)
 {
     Ok    = ok;
     Movie = movie;
 }