Exemplo n.º 1
0
        public IActionResult GetMovieCasting([FromRoute, SwaggerParameter("Id of Movie", Required = true)] int id)
        {
            MovieCasting movieCasting = new MovieCasting();

            movieCasting.Movies   = Service.Get(id).ToApi();
            movieCasting.Castings = Service.GetMovieCasting(id).Select(m => m.ToApi()).ToList();
            return(Ok(movieCasting));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> AddMovie(AddMovieViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;
                if (model.Photo != null)
                {
                    string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName; //guid = global unique identifier
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                    model.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
                    model.Movie.MovieCoverImage = uniqueFileName;
                }

                int movieId    = _context.Movies.Last().MovieId + 1;
                int actorId    = _context.Actors.Last().ActorId + 1;
                int directorId = _context.Directors.Last().DirectorId + 1;



                _context.Add(model.Movie);
                _context.Add(model.Actor);
                _context.Add(model.Director);

                MovieCasting movieCasting = new MovieCasting
                {
                    MovieId = movieId,
                    ActorId = actorId,
                    Actor   = model.Actor,
                    Movie   = model.Movie,
                    Role    = ""
                };
                MovieDirection movieDirection = new MovieDirection
                {
                    MovieId    = movieId,
                    DirectorId = directorId,
                    Director   = model.Director,
                    Movie      = model.Movie
                };

                Array _genres = Enum.GetValues(typeof(Genres));
                int   genreId = 0;

                foreach (int gen in _genres)
                {
                    if (Enum.GetName(typeof(Genres), gen) == model.Genre.GenreTitle.ToString())
                    {
                        break;
                    }
                    genreId++;
                }
                Genre g = new Genre {
                    GenreTitle = (Genres)Enum.Parse(typeof(Genres), model.Genre.GenreTitle.ToString())
                };
                MovieGenre movieGenre = new MovieGenre
                {
                    MovieId = movieId,
                    GenreId = _context.Genres.Last().GenreId + 1,
                    Movie   = model.Movie,
                    Genre   = g
                };

                _context.Add(movieCasting);
                _context.Add(movieDirection);
                _context.Add(movieGenre);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }