public IActionResult OnPost()
        {
            // If all the information is valid as per validation checks
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Movie.Genres = string.Join(',', GenresSelection.Where(selection => selection.IsSelected)
                                       .Select(selection => Enum.Parse(typeof(Genre), selection.GenreValue)));

            if (Movie.Id > 0)
            {
                movieData.Update(Movie);
            }
            else
            {
                movieData.Add(Movie);
            }

            movieData.Commit();

            // TempData works like a dictionary with the key/value pairs
            TempData["Message"] = "Movie saved!";
            return(RedirectToPage("./Detail", new { movieId = Movie.Id }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Movie movie = await PopulateMovieAsync();

            if (movie is null)
            {
                return(Page());
            }

            if (movie.Id > 0)
            {
                _movieData.Update(movie);
            }
            else
            {
                _movieData.Add(movie);
            }

            _movieData.Commit();

            // TempData works like a dictionary with the key/value pairs
            TempData["Message"] = "Movie saved!";
            return(RedirectToPage("./Detail", new { movieId = movie.Id })); // TODO: check if needed
        }
Exemplo n.º 3
0
        public void Post([FromBody] MovieCreateDTO movieDto)
        {
            var authorized = false;

            if (authorized)
            {
            }

            var movie = new Movie();

            movie.Title = movieDto.Title;
            movie.Year  = movieDto.Year;

            _movieData.Add(movie);

            //try
            //{

            //}
            //catch (System.Exception)
            //{

            //    throw;
            //}
        }
Exemplo n.º 4
0
 public ActionResult Create(Movie movie)
 {
     if (ModelState.IsValid)
     {
         var hasValues = db.GetAll();
         if (hasValues.Count() > 0)
         {
             var maxValue = db.GetAll().Max(e => e.EpisodeId);
             movie.EpisodeId = maxValue + 1;
         }
         else
         {
             movie.EpisodeId = 7;
         }
         db.Add(movie);
         TempData["Message"] = "You have created the movie!";
         return(RedirectToAction("Details", new { id = movie.MovieId }));
     }
     return(View());
 }
Exemplo n.º 5
0
        public ActionResult Create([Bind(Include = "MovieId,Title,ReleaseDate,Description")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                _db.Add(movie);
                return(RedirectToAction("Details", new { id = movie.MovieId }));
            }
            var post = _db.GetPost();

            ViewBag.MovieId = new SelectList(post, "PostId", "Text", movie.MovieId);
            return(View(movie));
        }
Exemplo n.º 6
0
        public IActionResult AddToDb(MovieTitle importMovie)
        {
            if (_sqlMovieData.Find(importMovie.Title) != null)
            {
                throw new Exception($"\"{importMovie.Title}\" is already in db!");
            }

            var helper   = new OMDBImportService(_mapper);
            var theMovie = helper.GetCompleteMovie(importMovie.Title);

            _sqlMovieData.Add(theMovie);
            return(View("index"));
        }
Exemplo n.º 7
0
 public IActionResult OnPost(int?id)
 {
     if (ModelState.IsValid)
     {
         if (Movie.Id > 0)
         {
             Movie = movieData.Update(Movie);
         }
         else
         {
             Movie = movieData.Add(Movie);
         }
         movieData.Commit();
         return(RedirectToPage("./Detail", new { id = Movie.Id }));
     }
     return(Page());
 }
Exemplo n.º 8
0
        public IActionResult Post(Metadata metadata)
        {
            //Take the POSTed Metadata object and use the -movieData service to add it to the collection,
            //returning a bool for its success state
            var success = _movieData.Add(metadata);

            //If we were successful, return an OK (200) response
            if (success)
            {
                return(Ok());
            }
            else
            {
                //Otherwise, if we weren't successful, return a BadRequest (400) response
                return(BadRequest());
            }
        }
 public IActionResult OnPost()
 {
     if (!ModelState.IsValid)
     {
         Ratings = htmlHelper.GetEnumSelectList <Rating>();
         return(Page());
     }
     if (Movie.MovieId > 0)
     {
         movieData.Update(Movie);
     }
     else
     {
         movieData.Add(Movie);
     }
     movieData.Commit();
     TempData["Message"] = "Movie saved: " + Movie.Title;
     return(RedirectToPage("./Detail", new { movieId = Movie.MovieId }));
 }
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                Genre = htmlHelper.GetEnumSelectList <Genre>();
                return(Page());
            }

            if (Movie.Id > 0)
            {
                movieData.Update(Movie);
            }
            else
            {
                movieData.Add(Movie);
            }
            TempData["Message"] = "Movie Saved!";
            movieData.Commit();
            return(RedirectToPage("./Detail", new { movieId = Movie.Id }));
        }
Exemplo n.º 11
0
 public ActionResult <Movie> Post([FromBody] Movie newMovie)
 {
     movieData.Add(newMovie);
     movieData.Commit();
     return(CreatedAtAction("Get", new { id = newMovie.Id }, newMovie));
 }