public string Update(MovieDto movie)
        {
            if (!movie.IsValid())
            {
                return("Invalid movie");
            }

            bool isUpdated = movieService.Update(movie);

            return(isUpdated ? "Movie updated successfully." : "Failed to update the movie");
        }
        public string Create(MovieDto movie)
        {
            if (!movie.IsValid())
            {
                return("Invalid movie");
            }

            bool isCreated = movieService.Create(movie);

            return(isCreated ? "Movie added successfully." : "Failed to create the movie.");
        }
Exemplo n.º 3
0
        public IActionResult Create([FromBody] MovieDto movie)
        {
            if (!movie.IsValid())
            {
                return(BadRequest());
            }

            if (movieService.Create(movie))
            {
                return(NoContent());
            }

            return(BadRequest());
        }
Exemplo n.º 4
0
        public IActionResult Update([FromRoute] int id, [FromBody] MovieDto movie)
        {
            if (!movie.IsValid())
            {
                return(BadRequest());
            }

            movie.Id = id;

            if (movieService.Update(movie))
            {
                return(NoContent());
            }

            return(BadRequest());
        }
Exemplo n.º 5
0
        public ActionResult <MovieDto> PostMovie(MovieDto movieDto)
        {
            if (!movieDto.IsValid())
            {
                return(StatusCode(StatusCodes.Status406NotAcceptable));
            }

            var movie = _service.CreateMovie((Movie)movieDto);

            if (movie == null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
            else
            {
                return(CreatedAtAction(nameof(GetMovie), new { id = movie.Id }, (MovieDto)movie));
            }
        }
Exemplo n.º 6
0
        public IActionResult PutMovie(int id, MovieDto movieDto)
        {
            if (id != movieDto.Id)
            {
                return(BadRequest());
            }

            if (!movieDto.IsValid())
            {
                return(StatusCode(StatusCodes.Status406NotAcceptable));
            }

            if (_service.UpdateMovie((Movie)movieDto))
            {
                return(Ok());
            }
            else
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }