Example #1
0
        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));
            }
        }