// mId here is called Query string ?mId = 20 public async Task <IActionResult> MovieDetail(int mId) { var m = new MovieRequestModel { Movie = await _movieService.GetMovieById(mId), Purchased = false, Favorited = false }; if (User.Identity.IsAuthenticated) { var userId = Convert.ToInt32(HttpContext.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value); var favorite = new Favorite { MovieId = mId, UserId = userId }; var purchase = new Purchase { MovieId = mId, UserId = userId }; m.Purchased = await _movieService.IsMoviePurchased(purchase); m.Favorited = await _movieService.IsMovieFavorited(favorite); } return(View(m)); }
public async Task <List <MovieModel> > GetMoviesAsync(MovieRequestModel movieRequestModel, int userId, CancellationToken cancellationToken) { try { //get movies var movieList = await movieRepository.GetMoviesAsync(movieRequestModel, cancellationToken); Log.Information($"Movies count:{movieList.Count} {nameof(GetMoviesAsync)}"); if (!movieList.Any()) { return(null); } // mapp Movie->MovieModel var mappedMovieList = mapper.Map <List <MovieModel> >(movieList); // get user rate for movies for (int i = 0; i < movieList.Count; i++) { mappedMovieList[i].RatingByUser = movieList[i].MovieRatings.FirstOrDefault(mr => mr.UserId == userId)?.Rating ?? 0; } return(mappedMovieList); } catch (Exception ex) { Log.Error(ex, $"Error occurs in {nameof(GetMoviesAsync)}"); throw; } }
public async Task <IActionResult> PutMovie(MovieRequestModel requestModel, int movieId) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values)); } if (movieId == 0) { return(BadRequest("movieId is required")); } try { var movie = await _adminService.UpdateMovie(movieId, requestModel); if (movie == null) { return(StatusCode(500, "Something went wrong!")); } return(Ok(movie)); } catch (Exception e) { Console.WriteLine(e); return(StatusCode(500, e.Message)); } }
public MovieViewModel Execute(MovieRequestModel requestModel) { var db = Database.OpenFile(HttpContext.Current.Server.MapPath("~/App_Data/fubu101.db")); var movies = db.movies.All(); return new MovieViewModel(movies); }
public async Task <ActionResult> UpdateMovieAsync(int id, MovieRequestModel request, CancellationToken cancellationToken) { _logger.LogInformation("Call made to UpdateMovieAsync."); await _movieService.UpdateMovieAsync(id, request, cancellationToken); return(Ok()); }
/// <inheritdoc /> public async Task UpdateMovieAsync(int id, MovieRequestModel request, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var movie = await GetMovieAsync(id, cancellationToken); SetMovieProperties(movie, request); await _context.SaveChangesAsync(cancellationToken); }
public async Task <ActionResult> CreateMovieAsync(MovieRequestModel request, CancellationToken cancellationToken) { _logger.LogInformation("Call made to CreateMovieAsync."); var id = await _movieService.CreateMovieAsync(request, cancellationToken); return(new ObjectResult(id) { StatusCode = StatusCodes.Status201Created }); }
public async Task <ActionResult <List <MovieModel> > > GetMoviesAsync([FromBody] MovieRequestModel movieRequestModel, CancellationToken cancellationToken) { try { var userId = JWTHelper.GetUserIdFromToken(HttpContext.User); var list = await movieService.GetMoviesAsync(movieRequestModel, userId, cancellationToken); return(Ok(list)); } catch (Exception ex) { Log.Error(ex, $"Error occurs in {nameof(GetMoviesAsync)}"); return(StatusCode(500, "Something went wrong!")); } }
/// <inheritdoc /> public async Task <int> CreateMovieAsync(MovieRequestModel movieModel, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var movie = new Movie { Title = movieModel.Title, Description = movieModel.Description, ReleaseDate = movieModel.ReleaseDate }; _context.MovieItems.Add(movie); await _context.SaveChangesAsync(cancellationToken); return(movie.Id); }
public Task <Movie> CreateMovie(MovieRequestModel requestModel) { var movie = new Movie() { Title = requestModel.Title, Overview = requestModel.Overview, Tagline = requestModel.Tagline, Budget = requestModel.Budget, Revenue = requestModel.Revenue, TmdbUrl = requestModel.TmdbUrl, PosterUrl = requestModel.PosterUrl, BackdropUrl = requestModel.BackdropUrl, OriginalLanguage = requestModel.OriginalLanguage, ReleaseDate = requestModel.ReleaseDate }; return(_movieRepository.AddAsync(movie)); }
public async Task <List <Movie> > GetMoviesAsync(MovieRequestModel movieRequestModel, CancellationToken cancellationToken) { try { /* * PROPUST!!! * * u smislu performansi zato sto se prvo ucitavaju svi filmovi iz baze pa se onda ta lista pretrazuje.. * * ideja je bila da napisem jedan jednostavan query i * da u Where uslovu pozovem funkciju searchMovie te joj proslijedim objekat Movie (kao sto je i u trenutnoj implementaciji) * * medjutim trenutna verzija EF Core-a koju koristim ima problem s prosljedjivanjem parametara na taj nacin * tacnije, prosljedjeni objekat iz Where uslova u funkciji ne sadrzi navigationProperty-e odnosno relatedEntities * pokusavao sam i sa EF Core lazy loading i sa eager loading medjutim dobio sam isti rezultat * * posto nisam imao dovoljno vremena da ovo rijesim, odlucio sam se za ovakvu implementaciju * * * */ var list = await dbContext.Movies.ToListAsync(cancellationToken); return(list .Where(m => m.TVShow == movieRequestModel.TvShow && searchMovie(m, movieRequestModel.SearchObject)) .OrderByDescending(m => m.MovieRatings.Any() ? m.MovieRatings.Average(mr => mr.Rating) : 0) .Skip(Int32.Parse(configuration.GetSection("AppSettings")["ItemsPerPage"]) * (movieRequestModel.Page - 1)) .Take(10) .ToList()); } catch (Exception ex) { throw ex; } }
private void SetMovieProperties(Movie movie, MovieRequestModel requestModel) { movie.Title = requestModel.Title; movie.Description = requestModel.Description; movie.ReleaseDate = requestModel.ReleaseDate; }