예제 #1
0
        public void Movie_Service_Should_Add_Movie_Successfully()
        {
            //Arrange
            var movie    = ObjectMother.GetDefaultMovie();
            var movieCmd = ObjectMother.GetMovieAddCommand();

            _mockMovieRepository.Setup(r => r.Add(It.IsAny <Movie>())).Returns(movie);

            //Action
            var addedMovie = _movieService.Add(movieCmd);

            //Assert
            _mockMovieRepository.Verify(r => r.Add(It.IsAny <Movie>()), Times.Once);
            addedMovie.Id.Should().Be(movie.Id);
        }
예제 #2
0
        public async Task <IActionResult> Post([FromBody()] MovieModel movie)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid object received by Post");
                    return(BadRequest("Invalid model"));
                }

                int newId = await _movieService.Add(movie);

                if (newId > 0)
                {
                    return(CreatedAtRoute("metadata", new MovieModel {
                        MovieId = newId
                    }, movie));
                }

                return(BadRequest("Unable to add movie"));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error within Post action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
        public ActionResult Save(MovieAdminView model, HttpPostedFileBase uploadedImage)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", model));
            }

            try
            {
                if (model.Id == 0)
                {
                    _movieService.Add(model, uploadedImage);
                }
                else
                {
                    _movieService.Update(model, uploadedImage);
                }
            }
            catch (ImageNotFoundException)
            {
                ModelState.AddModelError("Image", "Required field.");
            }

            return(View("Edit", model));
        }
예제 #4
0
        protected void btnAddMovie_Click(object sender, EventArgs e)
        {
            MovieCategory movieCategory = new MovieCategory();
            Movie         movie         = new Movie();

            movie.Name      = txtNameMovie.Text;
            movie.Writer    = txtWriterMovie.Text;
            movie.Director  = txtDirectorMovie.Text;
            movie.ImdbScore = Convert.ToDouble(txtImdb.Text);
            movie.Trailer   = txtTrailerMovie.Text;
            movie.Summary   = txtSummoryMovie.Text;
            movie.Year      = DateTime.Parse(txtYearMovie.Text);
            movie.IsActive  = checkIsActive.Checked;

            if (fileMoviePhoto.HasFile)
            {
                var      fileName    = fileMoviePhoto.FileName;
                FileInfo fileInfo    = new FileInfo(fileName);
                var      extension   = fileInfo.Extension;
                var      newFileName = $"{Guid.NewGuid()}{extension}";
                string   path        = $"{Server.MapPath("~/Uploads")}/{newFileName}";
                fileMoviePhoto.SaveAs(path);
                movie.CoverImage = newFileName;
            }
            _movieManager.Add(movie);
            movieCategory.CategoryId = Convert.ToInt32(listCategories.SelectedValue);
            movieCategory.MovieId    = movie.Id;
            _movieCategory.Add(movieCategory);
            LoadListOfMovies();
            Clear();
        }
        public MociesMutation(IMovieService service)
        {
            Name = nameof(MociesMutation);

            FieldAsync <MovieType>(
                "createMovie"
                , arguments: new global::GraphQL.Types.QueryArguments(new global::GraphQL.Types.QueryArgument <global::GraphQL.Types.NonNullGraphType <MovieInputType> > {
                Name = "movie"
            })
                , resolve: async context =>
            {
                var movieInput = context.GetArgument <MovieInput>("movie");
                var movie      = new Movie
                {
                    Id          = (await service.GetAsync()).Max(x => x.Id) + 1,
                    Name        = movieInput.Name,
                    ActorId     = movieInput.ActorId,
                    Company     = movieInput.Company,
                    ReleaseDate = movieInput.ReleaseDate,
                    MovieRating = movieInput.MovieRating
                };

                return(await service.Add(movie));
            });
        }
예제 #6
0
        public async Task <ActionResult> Post(CreateMovieRequest model)
        {
            Guid movieId = Guid.NewGuid();
            await _movieService.Add(movieId, model);

            return(CreatedAtRoute(nameof(GetMovieById), new { id = movieId }, movieId));
        }
예제 #7
0
        private static void DoSomething(object state)
        {
            IMovieService movieService = InstanceFactory.GetInstance <IMovieService>();


            Popular popular = JsonParse.Get <Popular>(TmdbLinked.GetPopular(count));

            foreach (var item in popular.results)
            {
                Movie movie = movieService.Get(x => x.TmdbID == item.id);
                if (movie != null)
                {
                    SetMovie(movie, item);
                    movieService.Update(movie);
                }
                else
                {
                    var m = new Movie();
                    SetMovie(m, item);
                    movieService.Add(m);
                }
            }

            count++;
        }
예제 #8
0
        public IActionResult Create(MovieViewModel movieViewModel)
        {
            var movie = new Movie();

            if (ModelState.IsValid)
            {
                movie.Title         = movieViewModel.Title;
                movie.YearOfRelease = movieViewModel.YearOfRelease;
                movie.IMBDScore     = movieViewModel.IMBDScore;
                movie.Country       = movieViewModel.Country;
                movie.Language      = movieViewModel.Language;
                movie.Price         = movieViewModel.Price;
                movie.Description   = movieViewModel.Description;
                movie.PhotoURL      = movieViewModel.PhotoURL;
                movie.SoldItems     = movieViewModel.SoldItems;
                movie.GenreID       = movieViewModel.GenreID;
                movie.GenreName     = movieViewModel.GenreName;
                movie.DirectorID    = movieViewModel.DirectorID;
                movie.DirectorName  = movieViewModel.DirectorName;


                _movieService.Add(movie);
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                _logger.LogInformation(LoggerMessageDisplay.MovieNotCreatedModelStateInvalid);
            }
            return(View());
        }
예제 #9
0
        public async Task <ImportResponse> ImportMoviesAsync(MovieImportRequest request)
        {
            ImportResponse response = await CheckRequest(request.UserID, request.Movies.Count);

            if (!response.Successful)
            {
                return(response);
            }

            var user = await _userManager.FindByIdAsync(request.UserID);

            foreach (var movie in request.Movies)
            {
                try
                {
                    movie.UserID  = request.UserID;
                    movie.UserNum = user.UserNum;
                    movie.ID      = 0;
                    _movieService.Add(movie);
                    response.Imported++;
                }
                catch (Exception ex)
                {
                    response.Failed++;
                    response.Message += $"{movie.Title} - {ex.Message} : {ex.InnerException?.Message}";
                }
            }

            response.Successful = true;

            return(response);
        }
        public ActionResult AddMovie(MovieLongDetailsDTO movie)
        {
            var allCategory = _categoryService.GetAllByMainCategoryId(1);
            List <SelectListItem> category = (from i in allCategory
                                              select new SelectListItem
            {
                Value = i.Id.ToString(),
                Text = i.Name
            }).ToList();

            ViewBag.Category = category;

            if (!ModelState.IsValid)
            {
                return(View(movie));
            }
            Movie addMovie = new Movie();

            addMovie.MovieName        = movie.MovieName;
            addMovie.MovieDescription = movie.MovieDescription;
            addMovie.CategoryId       = movie.CategoryId;
            addMovie.ImageURL         = FileHelper.Add(Request.Files[0], "Movie");
            addMovie.IMDBScore        = movie.IMDBScore;
            addMovie.TotalTime        = movie.TotalTime;
            addMovie.VideoURL         = movie.VideoURL;
            addMovie.Year             = movie.Year;
            addMovie.IsActive         = true;
            addMovie.CreatedDate      = DateTime.Now;
            _movieService.Add(addMovie);
            TempData["AddedMessage"] = $"{addMovie.MovieName} Filmi başarıyla eklendi";
            return(RedirectToAction("MovieList", "Movie"));
        }
예제 #11
0
        public IActionResult MovieCreate(EditMovieViewModel model, string MovieTitle, string CountryOfOrigin, string DirectorName, DateTime PremiereDate, DateTime EndDate, DateTime Length, string Poster, string Description)
        {
            var movie = new Movie()
            {
                Description  = Description,
                EndDate      = EndDate,
                Length       = Length,
                Poster       = Poster,
                PremiereDate = PremiereDate,
                Title        = MovieTitle,
                MovieGenres  = new List <MovieGenre>()
            };
            var director = directorService.Get().Find(a => a.DirectorName == DirectorName);

            if (director != null)
            {
                movie.DirectorId = director.Id;
                movie.Director   = director;
            }
            else
            {
                director = directorService.Add(new Director()
                {
                    DirectorName = model.DirectorName
                });
                movie.DirectorId = director.Id;
                movie.Director   = director;
            }
            var genres = Request.Form["genre"];

            foreach (var genre in genres)
            {
                var genreId = int.Parse(genre);
                movie.MovieGenres.Add(new MovieGenre()
                {
                    GenreId = genreId,
                    MovieId = movie.Id
                });
            }
            var countryOfOrigin = countryOfOriginService.Get().Where(m => m.Name == CountryOfOrigin).FirstOrDefault();

            if (countryOfOrigin != null)
            {
                movie.CountryOfOriginId = countryOfOrigin.Id;
                movie.CountryOfOrigin   = countryOfOrigin;
            }
            else
            {
                countryOfOrigin = countryOfOriginService.Add(new CountryOfOrigin()
                {
                    Name = model.CountryOfOrigin
                });
                movie.CountryOfOriginId = countryOfOrigin.Id;
                movie.CountryOfOrigin   = countryOfOrigin;
            }
            movieService.Add(movie);
            return(RedirectToAction("MovieTable"));
        }
예제 #12
0
 public IActionResult Create(AddMovieView addMovieView)
 {
     if (ModelState.IsValid)
     {
         _movieService.Add(addMovieView.ToMovie(CurrentUserId));
         return RedirectToAction("Index");
     }
     return View(addMovieView);
 }
예제 #13
0
        public IActionResult Post([FromBody] Movie myNewMovie)
        {
            var movie = _movieService.Add(myNewMovie);

            if (movie == null)
            {
                return(BadRequest());
            }
            return(CreatedAtAction("Get", new { Id = myNewMovie.Id }, myNewMovie));
        }
예제 #14
0
        public IActionResult Create(Movie movie)
        {
            var res = mRepo.Add(movie);

            if (res != null)
            {
                return(Ok(res));
            }
            return(BadRequest("Cannot add movie in db, check payload"));
        }
예제 #15
0
        public void AddMovie([FromBody] MovieModel postdata)
        {
            var movie = new Movie()
            {
                Name  = postdata.MovieName,
                Ganre = _genreService.GetGenreByName(postdata.MovieGanre)
            };

            _movieService.Add(movie);
        }
예제 #16
0
        public ActionResult Add(Movie movie)
        {
            if (ModelState.IsValid)
            {
                _movieService.Add(movie);
                TempData.Add("message", "Movie was successfully added");
            }

            return(RedirectToAction("Add"));
        }
        public async Task <IActionResult> CreateMovie([FromBody] MovieDto movie)
        {
            if (movie == null)
            {
                return(BadRequest());
            }

            await _movieService.Add(movie);

            return(Created("Created new movie.", movie));
        }
예제 #18
0
        public IHttpActionResult Post(MovieAddCommand MovieCmd)
        {
            var validator = MovieCmd.Validate(_service);

            if (!validator.IsValid)
            {
                return(HandleValidationFailure(validator.Errors));
            }

            return(HandleCallback(_service.Add(MovieCmd)));
        }
예제 #19
0
 public IActionResult Post([FromBody] Movie movie)
 {
     try
     {
         return(Ok(_movieService.Add(movie).ToApiModel()));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("Post", ex.Message);
         return(BadRequest(ModelState));
     }
 }
예제 #20
0
        public async Task <IActionResult> Create(Movie movie)
        {
            if (ModelState.IsValid)
            {
                movie.TrackingState = TrackingState.Added;
                await _service.Add(movie);

                return(RedirectToAction(nameof(Index)));
            }
            ViewBag.ActionType = nameof(Create);
            return(View("CreateEdit", movie));
        }
예제 #21
0
        public async Task <CreateMovieResponse> Add(CreateMovieRequest request)
        {
            var movie    = request.ProjectedAs <Movie>();
            var response = _service.Add(movie);

            if (response.IsSuccess)
            {
                _uow.Commit();
            }

            await Task.Delay(1);

            return(movie.ProjectedAs <CreateMovieResponse>());
        }
예제 #22
0
파일: UIMovie.cs 프로젝트: clleker/MovieAPP
        private void AddMovie()
        {
            _movieService.Add(new Movie
            {
                Name        = txtMovieName.Text,
                ReleaseDate = dtpReleaseDate.Value.Date,
                DirectorId  = (int)cmbDirector.SelectedValue,
                Rating      = (int)nudRating.Value,
                EndDate     = dtpEndDate.Value.Date,
                Price       = nudMoviePrice.Value
            });
            //AddActorToMovie();

            GetAllMovie();
        }
예제 #23
0
        public ActionResult Create(MovieModel model)
        {
            try
            {
                var item = Mapper.Map <Movie>(model);

                _movieService.Add(item);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
예제 #24
0
 public HttpResponseMessage Create(HttpRequestMessage request, Movie movie)
 {
     return(CreattHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (ModelState.IsValid)
         {
             response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             Movie result = _movieService.Add(movie);
             _movieService.SaveChanges();
             response = request.CreateResponse(HttpStatusCode.Created, result);
         }
         return response;
     }));
 }
        //POST: api/movies
        public IHttpActionResult Add(MovieDto movie)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = _movieService.Add(movie);

            if (result.Success)
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result.Message));
            }
        }
예제 #26
0
        public ActionResult Create([Bind(Include = "Name,Year,Genre")] MovieViewModel movieViewModel)
        {
            if (ModelState.IsValid)
            {
                var movie = new Movie
                {
                    Id    = movieViewModel.Id,
                    Genre = movieViewModel.Genre,
                    Name  = movieViewModel.Name,
                    Year  = movieViewModel.Year
                };

                _service.Add(movie);
                return(RedirectToAction("Index"));
            }

            return(View(movieViewModel));
        }
 public ActionResult Create(Movie movie)
 {
     //var movie = new Movie();
     //movie.title = model.title;
     //movie.runTime = model.runTime;
     //movie.genre = model.genre;
     //movie.rating = model.rating;
     //movie.description = model.description;
     if (movie != null)
     {
         if (!string.IsNullOrEmpty(movie.title) || !string.IsNullOrWhiteSpace(movie.title))
         {
             _movieService.Add(movie);
             _logger.LogInformation("New movie was created!");
         }
     }
     return(RedirectToAction(nameof(Index)));
 }
        public ActionResult AddMovie()
        {
            MovieEntity movie = new MovieEntity
            {
                Name        = Request.Form["Name"].ToString(),
                Director    = Request.Form["Director"].ToString(),
                Language    = Request.Form["Language"].ToString(),
                ReleaseDate = Request.Form["ReleaseDate"].ToString(),
                Duration    = Request.Form["Duration"].ToString(),
                Alias       = Request.Form["Alias"].ToString(),
                Description = Request.Form["Description"].ToString(),
                Rate        = Convert.ToInt32(Request.Form["Rate"]),
                DelFlag     = Convert.ToInt32(Request.Form["DelFlag"])
            };

            HttpPostedFileBase fileBase = Request.Files["PosterURL"];
            string             fileEx   = Path.GetExtension(fileBase.FileName);
            string             fileName = Guid.NewGuid().ToString() + fileEx;
            string             path     = Server.MapPath("~/Images/") + fileName;

            if (fileBase != null)
            {
                fileBase.SaveAs(path);
                movie.PosterURL = fileName;
            }
            else
            {
                movie.PosterURL = string.Empty;
            }

            if (_movieService.Add(movie))
            {
                return(Json(new ResultModel {
                    StatusCode = System.Net.HttpStatusCode.OK, Message = "Success"
                }));
            }
            else
            {
                return(Json(new ResultModel {
                    StatusCode = System.Net.HttpStatusCode.InternalServerError, Message = "An Error Occued when inserting MovieEntity"
                }));
            }
        }
예제 #29
0
 public HttpResponseMessage Post(HttpRequestMessage request, MovieViewModel movieVm)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             Movie newMovie = new Movie();
             newMovie.UpdateMovie(movieVm);
             var movie = _movieService.Add(newMovie);
             _movieService.Save();
             response = request.CreateResponse(HttpStatusCode.OK);
         }
         return response;
     }));
 }
예제 #30
0
        public async Task <ActionResult> Add([FromBody] SaveMovieDTO saveMovie)
        {
            try
            {
                var validatorResult = await _validator.ValidateAsync(saveMovie);

                if (!validatorResult.IsValid)
                {
                    return(BadRequest(validatorResult.Errors));
                }

                var movie = _mapper.Map <SaveMovieDTO, Movie>(saveMovie);
                await _movieService.Add(movie);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message));
            }
        }