Ejemplo n.º 1
0
        public async Task <APIResponse> Put(EditMovieDto editMovieDto)
        {
            try
            {
                var currentMovie = await _cinemaDbContext.Movies.FindAsync(editMovieDto.Id);

                if (editMovieDto.Image != null)
                {
                    string path = GetDefaultMoviePath();

                    using (var fileStream = new FileStream(path, FileMode.Create))
                    {
                        await editMovieDto.Image.CopyToAsync(fileStream);

                        editMovieDto.ImageURL = Path.GetRelativePath(_webHostEnvironment.WebRootPath, path);
                    }
                }

                _mapper.Map(editMovieDto, currentMovie);

                _cinemaDbContext.Movies.Update(currentMovie);
                await _cinemaDbContext.SaveChangesAsync();

                return(APIResponse.GetAPIResponse((int)HttpStatusCode.OK, "Movie Updated Successfully", currentMovie));
            }
            catch (Exception x)
            {
                return(APIResponse.GetAPIResponse((int)HttpStatusCode.BadRequest, x.InnerException?.Message ?? x.Message, null));
            }
        }
        public async Task <ActionResult <MovieDto> > EditMovie(int movieId, [FromBody] EditMovieDto movie)
        {
            if ((movie?.Duration ?? 0) <= 0)
            {
                return(BadRequest(new ErrorMessage("Duration must be longer than 0 minutes")));
            }
            var result = await _moviesService.Edit(movieId, movie);

            return(result == null?NotFound(new ErrorMessage("Movie not found")) : (ActionResult)Ok(result));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Put(Guid id, [FromBody] EditMovieDto editMovie)
        {
            var movie = await _movieService.UpdateAsync(id, editMovie);

            if (movie == null)
            {
                return(NotFound());
            }

            return(Ok(movie));
        }
Ejemplo n.º 4
0
        public async Task <MovieDetailDto> UpdateAsync(Guid id, EditMovieDto editMovie)
        {
            var movie = await _ctx.Movies.FindAsync(id);

            if (movie == null)
            {
                return(null);
            }

            movie.Title       = editMovie.Title;
            movie.Description = editMovie.Description;
            movie.ReleaseDate = editMovie.ReleaseDate;
            movie.RunTime     = editMovie.RunTime;
            movie.Score       = editMovie.Score;
            movie.Color       = editMovie.Color;

            await _ctx.SaveChangesAsync();

            return(Mapper.Map <MovieDetailDto>(movie));
        }
        public async Task <MovieDto> Edit(int movieId, EditMovieDto movie)
        {
            var entity = await _moviesRepository.GetById(movieId);

            if (entity == null)
            {
                return(null);
            }
            if (!string.IsNullOrEmpty(movie.Title))
            {
                entity.MovieTitle = movie.Title;
            }
            if (movie.Duration != null && movie.Duration > 0)
            {
                entity.MovieDuration = (int)movie.Duration;
            }
            var editedMovie = await _moviesRepository.Edit(entity);

            return(new MovieDto(editedMovie));
        }
Ejemplo n.º 6
0
 public async Task <APIResponse> Put([FromForm] EditMovieDto editMovieDto)
 {
     return(await _moviesService.Put(editMovieDto));
 }
Ejemplo n.º 7
0
 public void CreateMovie([FromBody] EditMovieDto movie)
 {
     movieRepositoryService.Insert(Mapper.Map <Movie>(movie));
     unitOfWork.Save();
 }