Пример #1
0
        public ActionResult save(movieviewmodel movieview)
        {
            if (!ModelState.IsValid)
            {
                movieview.genra = db.genras.ToList();
                return(View("movieform", movieview));
            }
            if (movieview.movies.id == 0)
            {
                movieview.movies.dateadded = DateTime.Now;
                var moviee = movieview.movies;
                db.movies.Add(moviee);
                db.SaveChanges();
            }
            else
            {
                var movieindb = db.movies.SingleOrDefault(m => m.id == movieview.movies.id);
                movieindb.name            = movieview.movies.name;
                movieindb.numberinstock   = movieview.movies.numberinstock;
                movieindb.releasedate     = movieview.movies.releasedate;
                movieindb.genraid         = movieview.movies.genraid;
                db.Entry(movieindb).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(RedirectToAction("index", "movies"));
        }
Пример #2
0
        public ActionResult New(int?id)
        {
            var movieview = new movieviewmodel();

            if (id == null)
            {
                movieview.movies = new movie();
                movieview.genra  = db.genras.ToList();
            }
            else
            {
                movieview.movies = db.movies.SingleOrDefault(m => m.id == id);
                movieview.genra  = db.genras.ToList();
            }
            return(View("movieform", movieview));
        }