public async Task <IActionResult> Create([Bind("ID,Title,ReleaseDate,Price,Genre,Rating")] Movie movie)
        {
            if (ModelState.IsValid)
            {
                await _movieService.Create(MovieMapper.Map(movie));

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
Exemple #2
0
        public void Post([FromBody] MoviePostModel movie)
        {
            User addedBy = usersService.GetCurentUser(HttpContext);

            ////if(addedBy.UserRole == UserRole.UserManager)
            // //{
            // //    return Forbid();      //trebuie returnat tipul IActionResult
            // //}

            moviesService.Create(movie, addedBy);
        }
Exemple #3
0
        public async Task <IActionResult> Create([FromBody]  MovieCreateUpdateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newlyAddedMovie = await _moviesService.Create(request);

            return(CreatedAtRoute("GetMovie", new { id = newlyAddedMovie }, newlyAddedMovie));
        }
Exemple #4
0
        public void AddMovie_ShouldCallRestAddEndpoint()
        {
            // Arrange
            _target = new MoviesService(_moviesApiServiceMock.Object);

            // Act
            _target.Create(new CreateMovieRequestDTO()).Subscribe();

            // Assert
            _moviesApiMock.Verify(x => x.CreateMovie(It.IsAny <CreateMovieRequestDTO>()), Times.Once);
        }
Exemple #5
0
        public ActionResult Create(FeatureFilmViewModel viewModel, HttpPostedFileBase image,
                                   IEnumerable <string> actor, IEnumerable <string> director,
                                   IEnumerable <string> category, IEnumerable <string> producer,
                                   IEnumerable <string> resolution, IEnumerable <string> tag)
        {
            var filmViewModel  = viewModel.FilmViewModel;
            var movieViewModel = viewModel.MoviesViewModel;

            var film  = AutoMapper.Mapper.Map <Film>(filmViewModel);
            var movie = AutoMapper.Mapper.Map <Movie>(movieViewModel);

            movie.IsSeriesMovie = false;
            film.MovieId        = movie.Id;

            if (image != null &&
                image.FileName != null &&
                CheckImageUploadExtension.CheckImagePath(image.FileName) == true)
            {
                var path = Path.Combine(Server.MapPath("~/Images/Upload"), image.FileName);
                image.SaveAs(path);
                movie.Thumbnail = VariableUtils.UrlUpLoadImage + image.FileName;
            }

            _movieService.Create(movie);
            _filmService.Create(film);

            if (actor != null)
            {
                foreach (var item in actor)
                {
                    _actorMovieService.Create(new ActorMovie()
                    {
                        ActorId = Guid.Parse(item),
                        MovieId = movie.Id
                    });
                }
            }
            if (director != null)
            {
                foreach (var item in director)
                {
                    _directorMovieService.Create(new DirectorMovie()
                    {
                        DirectorId = Guid.Parse(item),
                        MovieId    = movie.Id
                    });
                }
            }
            if (category != null)
            {
                foreach (var item in category)
                {
                    _categoryMovieService.Create(new CategoryMovie()
                    {
                        CategoryId = Guid.Parse(item),
                        MovieId    = movie.Id
                    });
                }
            }
            if (producer != null)
            {
                foreach (var item in producer)
                {
                    _producerMovieService.Create(new ProducerMovie()
                    {
                        ProducerId = Guid.Parse(item),
                        MovieId    = movie.Id
                    });
                }
            }
            if (resolution != null)
            {
                foreach (var item in resolution)
                {
                    _resolutionMovieService.Create(new MovieResolution()
                    {
                        ResolutionId = Guid.Parse(item),
                        MovieId      = movie.Id
                    });
                }
            }
            if (tag != null)
            {
                foreach (var item in tag)
                {
                    _tagMovieService.Create(new TagMovie()
                    {
                        TagId   = Guid.Parse(item),
                        MovieId = movie.Id
                    });
                }
            }
            return(RedirectToAction("Index"));
        }