コード例 #1
0
        public async Task <IActionResult> Details(string id)
        {
            try
            {
                AuthorizeHelper.Authorize(this.HttpContext, "Guest", this.GetType().Name, "Details", "movie");

                GetMovieModel getMovieModel = await _moviemindAPIService.GetModel <GetMovieModel>(id, "Movies");

                foreach (GetReviewModel getReviewModel in getMovieModel.Reviews)
                {
                    getReviewModel.User = await _moviemindAPIService.GetModel <GetUserModel>(getReviewModel.UserId.ToString(), "users");
                }

                var userId = HttpContext.Session.GetString("_Id");
                var user   = await _moviemindAPIService.GetModel <GetUserModel>(userId, "users");

                ViewBag.IsFavorite = false;

                foreach (GetMovieModel fav in user.Favorites)
                {
                    if (fav.Id == Guid.Parse(id))
                    {
                        ViewBag.IsFavorite = true;
                    }
                }

                return(View(getMovieModel));
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Edit(string id)
        {
            try
            {
                AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Edit", "movie");

                GetMovieModel getMovieModel = await _moviemindAPIService.GetModel <GetMovieModel>(id, "Movies");

                List <GetGenreModel> getGenreModels = await _moviemindAPIService.GetModels <GetGenreModel>("genres");

                List <GetDirectorModel> getDirectorModels = await _moviemindAPIService.GetModels <GetDirectorModel>("directors");

                PutMovieModel putMovieModel = new PutMovieModel
                {
                    Name          = getMovieModel.Name,
                    Year          = getMovieModel.Year,
                    Description   = getMovieModel.Description,
                    OverallRating = getMovieModel.OverallRating,
                    Duration      = getMovieModel.Duration,
                    DirectorId    = getMovieModel.DirectorId,
                    Director      = getMovieModel.Director,
                    GenreId       = getMovieModel.GenreId,
                    Genre         = getMovieModel.Genre
                };

                ViewBag.Genres    = getGenreModels;
                ViewBag.Directors = getDirectorModels;

                return(View(putMovieModel));
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e));
            }
        }
コード例 #3
0
        [ValidateAntiForgeryToken] // Prevents XSRF/CSRF attacks
        public async Task <IActionResult> Create(PostMovieModel postMovieModel)
        {
            try
            {
                AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Create", "movie");


                if (ModelState.IsValid)
                {
                    GetMovieModel getMovieModel = await _moviemindAPIService.PostModel <PostMovieModel, GetMovieModel>(postMovieModel, "Movies");

                    //put in new relationships
                    foreach (Guid actorId in postMovieModel.ActorIds)
                    {
                        await _moviemindAPIService.PostModel <PostActorMovieModel, GetActorMovieModel>(new PostActorMovieModel
                        {
                            ActorId = actorId,
                            MovieId = getMovieModel.Id
                        }, "ActorMovies");
                    }

                    return(Redirect("/Movies/Details/" + getMovieModel.Id.ToString()));
                }

                return(View(postMovieModel));
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e, this.View(postMovieModel)));
            }
        }
コード例 #4
0
        /// <summary>
        /// Takes GetMovieResponseList and parses the JSON format to usable data for the UI
        /// </summary>
        /// <param name="response">GetMovie API response list</param>
        public void Parse_GetMovie(List <IRestResponse> response)
        {
            GetMovieModel movie = new GetMovieModel();

            foreach (IRestResponse item in response)
            {
                dynamic m = JObject.Parse(item.Content);

                try
                {
                    movie.title        = m.results[0].title;
                    movie.release_date = m.results[0].release_date;
                    movie.vote_average = m.results[0].vote_average;
                    movie.id           = m.results[0].id;
                    movie.poster_path  = $"{baseImageURL}{m.results[0].poster_path}";
                    movie.vote_count   = m.results[0].vote_count;
                    movie.popularity   = m.results[0].popularity;
                    Movie_id           = movie.id;
                    // Create list of responses
                    GetMovieModel get = new GetMovieModel();
                    get.title        = movie.title;
                    get.release_date = movie.release_date;
                    get.vote_average = movie.vote_average;
                    get.poster_path  = movie.poster_path;
                    get.vote_count   = movie.vote_count;
                    get.popularity   = movie.popularity;
                    get.id           = Movie_id;
                    MovieResponses.Add(get);
                }
                catch (ArgumentOutOfRangeException) { }
            }
        }
コード例 #5
0
        public async Task <ActionResult <GetMovieModel> > PostMovie(PostMovieModel postMovieModel)
        {
            try
            {
                GetMovieModel movie = await _movieRepository.PostMovie(postMovieModel);

                return(CreatedAtAction(nameof(GetMovie), new { id = movie.Id }, movie));
            }
            catch (DatabaseException e)
            {
                return(BadRequest(e.MovieMindError));
            }
        }
コード例 #6
0
        [ValidateAntiForgeryToken] // Prevents XSRF/CSRF attacks
        public async Task <IActionResult> Delete(string id, GetMovieModel getMovieModel)
        {
            try
            {
                AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Delete", "movie");

                await _moviemindAPIService.DeleteModel(id, "Movies");

                return(RedirectToRoute(new { action = "Index", controller = "Movies" }));
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e, this.View(getMovieModel)));
            }
        }
コード例 #7
0
        public async Task <IActionResult> Delete(string id)
        {
            try
            {
                AuthorizeHelper.Authorize(this.HttpContext, "Editor", this.GetType().Name, "Delete", "movie");

                GetMovieModel getMovieModel = await _moviemindAPIService.GetModel <GetMovieModel>(id, "Movies");

                return(View(getMovieModel));
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e));
            }
        }
コード例 #8
0
        public async Task <IActionResult> Create(string movieId)
        {
            try
            {
                AuthorizeHelper.Authorize(this.HttpContext, "Guest", this.GetType().Name, "Create", "review");

                List <GetMovieModel> getMovieModels = await _moviemindAPIService.GetModels <GetMovieModel>("movies");

                ViewBag.Movies = getMovieModels;

                if (movieId != null)
                {
                    GetMovieModel getMovieModel = await _moviemindAPIService.GetModel <GetMovieModel>(movieId, "movies");

                    ViewBag.MovieId = Guid.Parse(movieId);
                }

                return(View());
            }
            catch (MovieMindException e)
            {
                return(ErrorHelper.HandleError(e));
            }
        }
コード例 #9
0
        public async Task <GetMovieModel> GetMovie(string id)
        {
            GetMovieModel movie = await _context.Movies
                                  .Select(x => new GetMovieModel
            {
                Id            = x.Id,
                Name          = x.Name,
                Year          = x.Year,
                OverallRating = x.OverallRating,
                Duration      = x.Duration,
                Description   = x.Description,
                DirectorId    = x.DirectorId,
                Director      = new GetDirectorModel
                {
                    Id          = x.Director.Id,
                    FirstName   = x.Director.FirstName,
                    LastName    = x.Director.LastName,
                    Birth       = x.Director.Birth,
                    Nationality = x.Director.Nationality,
                    Description = x.Director.Description
                },
                GenreId = x.GenreId,
                Genre   = new GetGenreModel
                {
                    Id   = x.Genre.Id,
                    Name = x.Genre.Name
                },
                Actors = (from actorMovie in _context.ActorMovies
                          where actorMovie.MovieId == x.Id
                          select new GetActorModel
                {
                    Id = actorMovie.ActorId,
                    FirstName = actorMovie.Actor.FirstName,
                    LastName = actorMovie.Actor.LastName,
                    Birth = actorMovie.Actor.Birth,
                    Description = actorMovie.Actor.Description,
                    Nationality = actorMovie.Actor.Nationality
                }).ToList(),
                Favorites = (from favorite in _context.Favorites
                             where favorite.MovieId == x.Id
                             select new GetUserModel
                {
                    Id = favorite.UserId,
                    FirstName = favorite.User.FirstName,
                    LastName = favorite.User.LastName,
                    Email = favorite.User.Email,
                    Description = favorite.User.Description,
                }).ToList(),
                Reviews = (from review in _context.Reviews
                           where review.MovieId == x.Id
                           select new GetReviewModel
                {
                    Id = review.MovieId,
                    Rating = review.Rating,
                    Date = review.Date,
                    Description = review.Description,
                    UserId = review.UserId
                }).ToList()
            })
                                  .AsNoTracking()
                                  .FirstOrDefaultAsync(x => x.Id == Guid.Parse(id));

            if (movie == null)
            {
                throw new EntityException("Movie not found", this.GetType().Name, "GetMovie", "404");
            }
            return(movie);
        }