コード例 #1
0
 public ActionResult Edit(ManageMovieViewModel model, System.Web.HttpPostedFileBase file)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     if (file != null && file.ContentLength > 0)
     {
         var fileName = System.IO.Path.Combine(Request.MapPath("~/Content/Movie/"), System.IO.Path.GetFileName(file.FileName));
         file.SaveAs(fileName);
         model.Avatar = System.IO.Path.GetFileName(file.FileName);
         string oldAvatar = _db.tbl_Movie.SingleOrDefault(m => m.movie_Id == model.Id).movie_Avatar;
         if (oldAvatar != "Movie_Default.png")
         {
             ImageManager.Delete(Server.MapPath("~/Content/Movie/" + oldAvatar));
         }
     }
     else
     {
         //MR_DataClassesDataContext _db = new MR_DataClassesDataContext();
         MRDataEntities _db = new MRDataEntities();
         model.Avatar = _db.tbl_Movie.SingleOrDefault(m => m.movie_Id == model.Id).movie_Avatar;
     }
     MovieManager.Edit(model);
     return(RedirectToAction("Index", new { id = model.Id }));
 }
コード例 #2
0
        public ActionResult CreateMovie(ManageMovieViewModel movie, System.Web.HttpPostedFileBase file)
        {
            if (!ModelState.IsValid)
            {
                return(View(movie));
            }
            if (file != null && file.ContentLength > 0)
            {
                var fileName = System.IO.Path.Combine(Request.MapPath("~/Content/Movie/"), System.IO.Path.GetFileName(file.FileName));
                file.SaveAs(fileName);
                movie.Avatar = System.IO.Path.GetFileName(file.FileName);
            }
            //MR_DataClassesDataContext _db = new MR_DataClassesDataContext();
            MRDataEntities _db = new MRDataEntities();

            if ((bool)_db.tbl_UserAccount.SingleOrDefault(u => u.user_Account == CookieHepler.GetCookie("user")).user_IsAdmin)
            {
                movie.Status = 2;
            }
            else
            {
                movie.Status = 0;
            }
            movie.Create = AccountManager.GetId(CookieHepler.GetCookie("user"));
            string newId = MovieManager.CreateMovie(movie);

            return(RedirectToAction("Index", new { id = newId }));
        }
コード例 #3
0
        /// <summary>
        /// 创建电影
        /// </summary>
        /// <param name="movie"></param>
        /// <returns>电影id</returns>
        public static string CreateMovie(ManageMovieViewModel movie)
        {
            //using (MR_DataClassesDataContext _db = new MR_DataClassesDataContext())
            using (MRDataEntities _db = new MRDataEntities())
            {
                string guid;
                do
                {
                    guid = Guid.NewGuid().ToString("N").ToUpper();
                } while (_db.tbl_Movie.Where(p => p.movie_Id == guid).Count() != 0);

                if (!string.IsNullOrEmpty(movie.Genres) && !string.IsNullOrWhiteSpace(movie.Genres))
                {
                    movie.Genres = Translator.GenreToId(movie.Genres);
                }
                if (!string.IsNullOrEmpty(movie.Countries) && !string.IsNullOrWhiteSpace(movie.Countries))
                {
                    movie.Countries = Translator.CountryToId(movie.Countries);
                }
                if (!string.IsNullOrEmpty(movie.Languages) && !string.IsNullOrWhiteSpace(movie.Countries))
                {
                    movie.Languages = Translator.LangToId(movie.Languages);
                }

                var createMovie = new tbl_Movie()
                {
                    movie_Id          = guid,
                    movie_Title       = movie.Title,
                    movie_TitleEn     = movie.TitleEn,
                    movie_Aka         = movie.Aka,
                    movie_Directors   = movie.Directors,
                    movie_Writers     = movie.Writers,
                    movie_Casts       = movie.Casts,
                    movie_Durations   = movie.Durations,
                    movie_Genres      = movie.Genres,
                    movie_Countries   = movie.Countries,
                    movie_Languages   = movie.Languages,
                    movie_Pubdates    = movie.Pubdates,
                    movie_Year        = movie.Year,
                    movie_Rating      = movie.Rating,
                    movie_RatingCount = movie.RatingCount,
                    movie_Summary     = movie.Summary,
                    movie_DoubanID    = movie.DoubanID,
                    movie_IMDbID      = movie.IMDbID,
                    movie_VisitCount  = 0,
                    movie_Create      = movie.Create,
                    movie_Status      = movie.Status,
                    movie_Avatar      = movie.Avatar == null ? "Movie_Default.png" : movie.Avatar
                };
                //_db.tbl_Movie.InsertOnSubmit(createMovie);
                //_db.SubmitChanges();
                //_db.SetMovieTime(guid);
                _db.tbl_Movie.Add(createMovie);
                _db.SaveChanges();

                return(createMovie.movie_Id);
            }
        }
コード例 #4
0
        public ActionResult Delete(string id, string returnurl)
        {
            if (!MovieManager.Exist(id))
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            ManageMovieViewModel movie = new ManageMovieViewModel(_db.tbl_Movie.SingleOrDefault(s => s.movie_Id == id));

            ViewBag.ReturnUrl = returnurl;
            return(View(movie));
        }
コード例 #5
0
        public ActionResult RefreshConfirm(string id)
        {
            if (!MovieManager.Exist(id))
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            ManageMovieViewModel movie = TempData["New"] as ManageMovieViewModel;

            MovieManager.Edit(movie);
            return(RedirectToAction("Index", new { id = movie.Id }));
        }
コード例 #6
0
        public ActionResult Edit(string id)
        {
            if (!MovieManager.Exist(id))
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            tbl_Movie            tblmovie = _db.tbl_Movie.SingleOrDefault(s => s.movie_Id == id);
            ManageMovieViewModel movie    = new ManageMovieViewModel(tblmovie);

            return(View(movie));
        }
コード例 #7
0
ファイル: MovieController.cs プロジェクト: ali50m/education
        // GET: Movie/Edit/{id}
        public ActionResult Edit(int id)
        {
            Movie movie = _context.Movies.SingleOrDefault(m => m.Id == id);

            if (movie == null)
            {
                return(HttpNotFound($"There is no " +
                                    $"{this.GetType().Name.Replace("Controller", "")} with Id = {id}"));
            }

            ManageMovieViewModel viewModel = new ManageMovieViewModel(_context.Genres, movie);

            return(View("ManageMovie", viewModel));
        }
コード例 #8
0
        public ActionResult RefreshConfirm(string id)
        {
            if (!MovieManager.Exist(id))
            {
                return(RedirectToAction("NotFound", "Error"));
            }
            ManageMovieViewModel newmovie = TempData["NewMovie"] as ManageMovieViewModel;

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Edit", new { id = newmovie.Id }));
            }
            MovieManager.Edit(newmovie);
            return(RedirectToAction("Edit", new { id = newmovie.Id }));
        }
コード例 #9
0
        public ActionResult CreateMovie(ManageMovieViewModel movie, System.Web.HttpPostedFileBase file)
        {
            if (!ModelState.IsValid)
            {
                return(View(movie));
            }
            if (file != null && file.ContentLength > 0)
            {
                var fileName = System.IO.Path.Combine(Request.MapPath("~/Content/Movie/"), System.IO.Path.GetFileName(file.FileName));
                file.SaveAs(fileName);
                movie.Avatar = System.IO.Path.GetFileName(file.FileName);
            }
            movie.Create = AccountManager.GetId(User.Identity.Name);
            movie.Status = 2;
            string newId = MovieManager.CreateMovie(movie);

            return(RedirectToAction("Edit", new { id = newId }));
        }
コード例 #10
0
ファイル: MovieController.cs プロジェクト: ali50m/education
        public async Task <ActionResult> Save(ManageMovieViewModel movieVeiwModel)
        {
            Movie model = movieVeiwModel.GetPopulatedMovie();

            if (!ModelState.IsValid)
            {
                var viewModel = new ManageMovieViewModel(_context.Genres, model);

                return(View("ManageMovie", viewModel));
            }

            if (model.Id > 0)
            {
                // Existing Record
                Movie movieFromDb = _context.Movies.SingleOrDefault(m => m.Id == model.Id);
                if (movieFromDb != null)
                {
                    movieFromDb.Name          = model.Name;
                    movieFromDb.ReleaseDate   = model.ReleaseDate;
                    movieFromDb.GenreId       = model.GenreId;
                    movieFromDb.NumberInStock = model.NumberInStock;
                }
            }
            else
            {
                // New Record
                _context.Movies.Add(model);
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbEntityValidationException e)
            {
                return(Content(GetValidationExceptionInfo(e)));
            }

            return(RedirectToAction("Index", "Movie"));
        }
コード例 #11
0
        /// <summary>
        /// 修改电影
        /// </summary>
        /// <param name="movie"></param>
        public static void Edit(ManageMovieViewModel movie)
        {
            //using (MR_DataClassesDataContext _db = new MR_DataClassesDataContext())
            using (MRDataEntities _db = new MRDataEntities())
            {
                bool hasChange = false;
                var  oldMovie  = _db.tbl_Movie.SingleOrDefault(p => p.movie_Id == movie.Id);

                #region 是否发生变化
                if (oldMovie.movie_Title != movie.Title)
                {
                    oldMovie.movie_Title = movie.Title;
                    hasChange            = true;
                }
                if (oldMovie.movie_TitleEn != movie.TitleEn)
                {
                    oldMovie.movie_TitleEn = movie.TitleEn;
                    hasChange = true;
                }
                if (oldMovie.movie_Aka != movie.Aka)
                {
                    oldMovie.movie_Aka = movie.Aka;
                    hasChange          = true;
                }
                if (oldMovie.movie_Directors != movie.Directors)
                {
                    oldMovie.movie_Directors = movie.Directors;
                    hasChange = true;
                }
                if (oldMovie.movie_DirectorsId != movie.DirectorsId)
                {
                    oldMovie.movie_DirectorsId = movie.DirectorsId;
                    hasChange = true;
                }
                if (oldMovie.movie_Writers != movie.Writers)
                {
                    oldMovie.movie_Writers = movie.Writers;
                    hasChange = true;
                }
                if (oldMovie.movie_WritersId != movie.WritersId)
                {
                    oldMovie.movie_WritersId = movie.WritersId;
                    hasChange = true;
                }
                if (oldMovie.movie_CastsId != movie.CastsId)
                {
                    oldMovie.movie_CastsId = movie.CastsId;
                    hasChange = true;
                }
                if (oldMovie.movie_Year != movie.Year)
                {
                    oldMovie.movie_Year = movie.Year;
                    hasChange           = true;
                }
                if (oldMovie.movie_Pubdates != movie.Pubdates)
                {
                    oldMovie.movie_Pubdates = movie.Pubdates;
                    hasChange = true;
                }
                if (oldMovie.movie_Durations != movie.Durations)
                {
                    oldMovie.movie_Durations = movie.Durations;
                    hasChange = true;
                }
                string id = string.IsNullOrEmpty(movie.Genres) || string.IsNullOrWhiteSpace(movie.Genres) ? null : Translator.GenreToId(movie.Genres);
                if (oldMovie.movie_Genres != id)
                {
                    oldMovie.movie_Genres = id;
                    hasChange             = true;
                }
                id = string.IsNullOrEmpty(movie.Countries) || string.IsNullOrWhiteSpace(movie.Countries) ? null : Translator.CountryToId(movie.Countries);
                if (oldMovie.movie_Countries != id)
                {
                    oldMovie.movie_Countries = id;
                    hasChange = true;
                }
                id = string.IsNullOrEmpty(movie.Languages) || string.IsNullOrWhiteSpace(movie.Languages) ? null : Translator.LangToId(movie.Languages);
                if (oldMovie.movie_Languages != id)
                {
                    oldMovie.movie_Languages = id;
                    hasChange = true;
                }
                if (oldMovie.movie_Rating != movie.Rating)
                {
                    oldMovie.movie_Rating = movie.Rating;
                    hasChange             = true;
                }
                if (oldMovie.movie_RatingCount != movie.RatingCount)
                {
                    oldMovie.movie_RatingCount = movie.RatingCount;
                    hasChange = true;
                }
                if (oldMovie.movie_DoubanID != movie.DoubanID)
                {
                    oldMovie.movie_DoubanID = movie.DoubanID;
                    hasChange = true;
                }
                if (oldMovie.movie_IMDbID != movie.IMDbID)
                {
                    oldMovie.movie_IMDbID = movie.IMDbID;
                    hasChange             = true;
                }
                if (oldMovie.movie_Avatar != movie.Avatar)
                {
                    oldMovie.movie_Avatar = movie.Avatar;
                    hasChange             = true;
                }
                if (oldMovie.movie_Summary != movie.Summary)
                {
                    oldMovie.movie_Summary = movie.Summary;
                    hasChange = true;
                }
                #endregion
                if (hasChange)
                {
                    //_db.SubmitChanges();
                    //_db.AlterMovieAlterTime(movie.Id);
                    _db.SaveChanges();
                }
            }
        }
コード例 #12
0
ファイル: MovieController.cs プロジェクト: ali50m/education
        // GET: Movie/New
        public ActionResult New()
        {
            var viewModel = new ManageMovieViewModel(_context.Genres, null);

            return(View("ManageMovie", viewModel));
        }