示例#1
0
        public ActionResult Create(MovieEnvelop movie)
        {
            try
            {
                if (CheckUser())
                {
                    return(RedirectToAction("Index", "Movie"));
                }

                if (ModelState.IsValid)
                {
                    if (movie.Picture != null)
                    {
                        string fileName = movie.Id.ToString();
                        string extFile  = Path.GetExtension(movie.Picture.FileName);
                        movie.Poster = string.Format("{0}{1}", fileName, extFile);
                        movie.Picture.SaveAs(Server.MapPath($"~/Files/{fileName}{extFile}"));
                    }

                    movie.Id          = Guid.NewGuid();
                    movie.CreatedDate = DateTime.Now;
                    movie.UserId      = User.Identity.GetUserId();
                    movieContext.Create(movie.Translate());
                    return(RedirectToAction("Index", "Movie"));
                }
                else
                {
                    return(View(movie));
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Movie"));
            }
        }