public async Task <ActionResult <Movies> > AddNewMovie(Movies newMovieData) { try { var addedMovie = await moviesService.AddMovieAsync(newMovieData); if (addedMovie == null) { return(BadRequest(new { message = "MOVIE_ALREADY_EXIST" })); } var location = link.GetPathByAction("GetByMovieTitle", "Movies", new { title = newMovieData.Title }); if (string.IsNullOrWhiteSpace(location)) { return(BadRequest(new { message = "MOVIETITLE_OCCUPIED" })); } if ((await moviesService.CommitAsync()) > 0) { return(Created(location, newMovieData)); } } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } return(BadRequest()); }
public async Task <ActionResult> Post([FromForm] MovieCreationDTO movieCreationDTO) { var exists = await _moviesService.CheckImdbIdAsync(movieCreationDTO.ImdbId); if (exists == 1) { return(BadRequest($"ImdbId {movieCreationDTO.ImdbId} already exists.")); } var movieDTO = await _moviesService.AddMovieAsync(movieCreationDTO); return(new CreatedAtRouteResult("getMovie", new { Id = movieDTO.Id }, movieDTO)); }
public async Task <IActionResult> CreateMovie(Movie movie) { await moviesService.AddMovieAsync(movie); return(CreatedAtAction(nameof(GetOne), new { id = movie.Id }, movie)); }