コード例 #1
0
        public ActionResult AddFilm(Movie movi)
        {
            if (ModelState.IsValid == true)
            {
                if (Request.Files.Count > 0)
                {
                    var file = Request.Files[0];

                    if (file != null && file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        movi.Images = fileName;

                        var path = Path.Combine(Server.MapPath("~/Content/image/"), fileName);
                        file.SaveAs(path);
                    }
                }

                Addedfilm.Saver(movi);
                return RedirectToAction("Films");
            }
            else
            {
                return View(movi);
            }
        }
コード例 #2
0
 public static void Saver(Movie add)
 {
     using (var db = new DbMovieContext())
     {
          db.Movies.Add(add);
         db.SaveChanges();
     }
 }
コード例 #3
0
        public ActionResult Create(Movie movie)
        {
            if (!ModelState.IsValid)
            {
                return View(movie);
            }
            try
            {
                _service.AddMovie(movie);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
コード例 #4
0
 public virtual void AddMovie(Movie movie)
 {
     MovieList.Add(movie);
 }