public IActionResult Edit(
            string title, DateTime releaseDate, 
            string description, bool preorder)
        {
            DateTime modifiedReleaseDate = releaseDate;
            if (releaseDate == null) {
                modifiedReleaseDate = DateTime.Today;
            }

            var movie = new Movie
            {
                Title = title,
                ReleaseDate = modifiedReleaseDate,
                Description = description,
                Preorder = preorder
            };
                               
            TryValidateModel(movie);

            if (ModelState.IsValid)
            {
                _context.Movie.Add(movie);
                _context.SaveChanges();           
                return RedirectToAction("Index","Home");    
            }
            else
            {
                return HttpBadRequest(ModelState);
            }            
        }
Exemplo n.º 2
0
        public IActionResult Create(
            string title,
            Genre genre,
            DateTime releaseDate,
            string description,
            decimal price,
            bool preorder)
        {
            var modifiedReleaseDate = releaseDate;
            if (releaseDate == null)
            {
                modifiedReleaseDate = DateTime.Today;
            }

            var movie = new Movie
            {
                Title = title,
                Genre = genre,
                ReleaseDate = modifiedReleaseDate,
                Description = description,
                Price = price,
                Preorder = preorder,
            };

            TryValidateModel(movie);
            if (ModelState.IsValid)
            {
                _context.AddMovie(movie);
                _context.SaveChanges();

                return RedirectToAction(actionName: nameof(Index));
            }

            return View(movie);
        }
Exemplo n.º 3
0
 public void AddMovie(Movie movie)
 {
     movie.Id = Movies.Count;
     Movies.Add(movie);
 }