コード例 #1
0
        public ActionResult Create(MovieVM movieVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (MoviesReference.MoviesClient service = new MoviesReference.MoviesClient())
                    {
                        MoviesReference.MovieDto movieDto = new MoviesReference.MovieDto
                        {
                            Title          = movieVM.Title,
                            ReleaseDate    = movieVM.ReleaseDate,
                            ReleaseCountry = movieVM.ReleaseCountry,
                            Genre          = new MoviesReference.GenreDto
                            {
                                Id = movieVM.GenreId
                            }
                        };
                        service.PostMovie(movieDto);
                    }

                    return(RedirectToAction("Index"));
                }

                ViewBag.Genres = LoadDataUtil.LoadGenreData();
                return(View());
            }
            catch
            {
                ViewBag.Genres = LoadDataUtil.LoadGenreData();
                return(View());
            }
        }
コード例 #2
0
        public ActionResult Create(MovieVM movieVM)
        {
            try
            {
                using (MoviesReference.MoviesClient service = new MoviesReference.MoviesClient())
                {
                    MoviesReference.MovieDto movieDto = new MoviesReference.MovieDto
                    {
                        Title          = movieVM.Title,
                        ReleaseDate    = movieVM.ReleaseDate,
                        ReleaseCountry = movieVM.ReleaseCountry,
                        Genre          = new MoviesReference.GenreDto {
                            Id = movieVM.GenreId
                        }
                    };
                    service.PostMovie(movieDto);
                }

                using (GenresReference.GenresClient service = new GenresReference.GenresClient())
                {
                    ViewBag.Genres = new SelectList(service.GetGenres(), "Id", "Name");
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }