public async Task <IEnumerable <MovieServiceModel> > GetAllPurchasedMoviesForUser(string userId) { List <History> userHistories = await this.Db.Histories.Where(x => x.CustomerId == userId).ToListAsync(); List <MovieServiceModel> movies = new List <MovieServiceModel>(); foreach (History history in userHistories) { Movie movie = await this.Db.Movies .FindAsync(history.MovieId); MovieServiceModel movieModel = new MovieServiceModel { Id = movie.Id, Name = movie.Name, Genres = movie.Genres, Rating = movie.Rating, PosterPath = movie.PosterPath, VideoPath = movie.VideoPath, TrailerPath = movie.TrailerPath, Summary = movie.Summary, Year = movie.Year }; movies.Add(movieModel); } return(movies); }
private async Task <BuyMovieViewModel> GetPaymentModel(Guid id) { MovieServiceModel movieModel = await this.movieService.FindMovie(id); User user = await userManager.GetUserAsync(HttpContext.User); IList <string> roles = await userManager.GetRolesAsync(user); string role = roles.SingleOrDefault(); movieModel.Price = movieModel.Prices.SingleOrDefault(x => x.Role.Name == role).MoviePrice; UserBalanceServiceModel userBalanceModel = new UserBalanceServiceModel(); userBalanceModel = this.userBalanceService.GetUserBalance(user.Id); BuyMovieViewModel buyMovieViewModel = new BuyMovieViewModel(); buyMovieViewModel.Balance = userBalanceModel.Balance; buyMovieViewModel.MovieId = id; buyMovieViewModel.Price = movieModel.Price; buyMovieViewModel.MovieName = movieModel.Name; return(buyMovieViewModel); }
public async Task <IActionResult> MovieDetails(Guid id) { MovieServiceModel movieModel = await this.movieService.FindMovie(id); movieModel.NumLinesSummary = Regex.Matches(movieModel.Summary, "\r\n").Count; movieModel.NumLinesSummary = movieModel.NumLinesSummary + movieModel.NumLinesSummary + 1; movieModel.Comments = await this.commentService.GetAllCommentsForMovie(movieModel.Id); movieModel.Comments = movieModel.Comments .OrderByDescending(x => x.Date) .ThenBy(p => p.Date.Hour) .ThenBy(c => c.Date.Minute) .ThenBy(s => s.Date.Second) .ToList(); if (User.Identity.IsAuthenticated) { User user = await userManager.GetUserAsync(HttpContext.User); movieModel.History = await this.historyService.GetHistoryForMovieAboutUser(user.Id, id); IList <string> roles = await userManager.GetRolesAsync(user); foreach (string role in roles) { movieModel.Price = movieModel.Prices.SingleOrDefault(x => x.Role.Name == role).MoviePrice; } movieModel.IsPurchased = this.movieService.IsPurchased(user.Id, movieModel.Id); } return(View(movieModel)); }
public async Task <IActionResult> Index(MovieFilterServiceModel movieFilter) { MovieFilterServiceModel movieFilterServiceModel = await this.movieService.FilteredMovies(movieFilter); List <GenreServiceModel> genres = await genreService.GetAllGenres(); if (User.Identity.IsAuthenticated) { User user = await userManager.GetUserAsync(HttpContext.User); IList <string> roles = await userManager.GetRolesAsync(user); string role = roles.SingleOrDefault(); if (role == null) { await this.userManager.AddToRoleAsync(user, GlobalConstants.RegularUser); role = GlobalConstants.RegularUser; } if (movieFilterServiceModel.MovieCollection != null) { foreach (MovieServiceModel movie in movieFilterServiceModel.MovieCollection) { MovieServiceModel movieModel = await this.movieService.FindMovie(movie.Id); movie.IsPurchased = this.movieService.IsPurchased(user.Id, movie.Id); movie.Price = movieModel.Prices.SingleOrDefault(x => x.Role.Name == role).MoviePrice; } } else { movieFilterServiceModel.MovieCollection = new List <MovieServiceModel>(); } foreach (GenreServiceModel genre in genres) { GenreServiceModel genreModel = new GenreServiceModel(); genreModel.Name = genre.Name; genreModel.Id = genre.Id; movieFilterServiceModel.Genres.Add(genreModel); } } return(View(movieFilterServiceModel)); }
public async Task <IActionResult> CreateComment(MovieServiceModel model) { if (!ModelState.IsValid) { //var errors = ModelState.Select(x => x.Value.Errors) // .Where(y => y.Count > 0) // .ToList(); return(RedirectToAction(nameof(MovieDetails), new { id = model.Id })); } User user = await userManager.GetUserAsync(HttpContext.User); await this.commentService.AddCommentForMovie(model.Comment, user.Id, model.Id); return(RedirectToAction(nameof(MovieDetails), new { id = model.Id })); }
public async Task <MovieServiceModel> FindMovie(Guid id) { Movie movie = await this.Db.Movies .Include(x => x.Genres) .ThenInclude(p => p.Genre) .SingleOrDefaultAsync(m => m.Id == id); MovieServiceModel movieModel = new MovieServiceModel { Id = movie.Id, Name = movie.Name, Genres = movie.Genres, Rating = movie.Rating, PosterPath = movie.PosterPath, VideoPath = movie.VideoPath, TrailerPath = movie.TrailerPath, Summary = movie.Summary, Year = movie.Year }; movieModel.Prices = await this.priceService.GetAllPricesForMovie(movieModel.Id); return(movieModel); }