public async Task <ActionResult> AddMovie( [Bind("Name,Description,Duration,Year, Price,GenreName, Image")] [FromBody] MovieDTO movieDTO, [FromForm] IFormCollection formCollection) { if (movieDTO == null) { return(BadRequest("Unsufficient data provided")); } Movie movie = mapper.Map <Movie>(movieDTO); if (!ModelState.IsValid) { return(BadRequest(ModelState)); //400 } if (movieRepo.MovieExist(movie)) { return(NotFound()); } try { logger.LogInformation($"Adding the movie {movie.Name}"); movieRepo.AddMovieWithGenre(movie); await movieRepo.Create(movie); await movieRepo.SaveAsync(); await hubContext.Clients.All.SendAsync("ServerMessage", movieDTO); } catch (Exception exc) { Log.Logger.Warning($"Threw exception when adding the movie {movie.Name}: {exc}"); logger.LogError($"Threw exception when adding the movie {movie.Name}: {exc}"); throw new Exception($"Creating the movie {movie.Name} did not succeed."); } movieDTO = mapper.Map <MovieDTO>(movie); return(Created($"api/{movieDTO.MovieID}", movieDTO)); }
public void Create([FromBody] MovieData value) { movieRepo.Create(value); }