예제 #1
0
        public IActionResult New(NewMovieModel model)
        {
            if (ModelState.IsValid && _categoryService.GetById(model.CategoryId.Value) != null)
            {
                var movie = _mapper.NewMovieModelToMovie(model, true, _categoryService);
                _movieService.NewMovie(movie);
                return(RedirectToAction("Index", new { id = movie.Id }));
            }
            GetCategoriesForDropDownList();

            ViewBag.ActionText     = "create";
            ViewBag.Action         = "New";
            ViewBag.ControllerName = "Category";
            ViewBag.CancelAction   = "Topic";
            ViewBag.SubmitText     = "Create Movie";
            ViewBag.RouteId        = model.CategoryId;

            return(View("CreateEdit", model));
        }
예제 #2
0
        public IActionResult Edit(NewMovieModel model)
        {
            if (ModelState.IsValid)
            {
                var movie = _mapper.NewMovieModelToMovie(model, false, _categoryService);
                _movieService.EditMovie(movie);
                return(RedirectToAction("Index", new { id = model.Id }));
            }

            ViewBag.ActionText     = "change";
            ViewBag.Action         = "Edit";
            ViewBag.CancelAction   = "Index";
            ViewBag.SubmitText     = "Save Changes";
            ViewBag.ControllerName = "Movie";
            ViewBag.RouteId        = model.Id;
            GetCategoriesForDropDownList();

            return(View("CreateEdit", model));
        }
예제 #3
0
        public Movie NewMovieModelToMovie(NewMovieModel model, bool newInstance, ICategory categoryService)
        {
            var movie = new Movie
            {
                Name             = model.Name,
                Category         = categoryService.GetById(model.CategoryId.Value),
                CategoryId       = model.CategoryId.Value,
                ImageUrl         = model.ImageUrl,
                InStock          = model.InStock.Value,
                IsPreferedMovie  = model.IsPreferedMovie.Value,
                LongDescription  = model.LongDescription,
                Price            = model.Price.Value,
                ShortDescription = model.ShortDescription,
            };

            if (!newInstance)
            {
                movie.Id = model.Id;
            }

            return(movie);
        }
예제 #4
0
        public IActionResult New(int categoryId = 0)
        {
            GetCategoriesForDropDownList();
            NewMovieModel model = new NewMovieModel
            {
                CategoryId = categoryId
            };

            ViewBag.ActionText     = "create";
            ViewBag.Action         = "New";
            ViewBag.CancelAction   = "Topic";
            ViewBag.SubmitText     = "Create Movie";
            ViewBag.RouteId        = categoryId;
            ViewBag.ControllerName = "Category";

            if (categoryId == 0)
            {
                ViewBag.CancelAction   = "Index";
                ViewBag.ControllerName = "Home";
            }

            return(View("CreateEdit", model));
        }