public async Task <IActionResult> PostAsync([FromBody] FilmDTO model) { await Task.Yield(); try { var filmToCreate = model.ToEntity(); filmToCreate.Director = await directorLogic.GetAsync(model.DirectorID).ConfigureAwait(false); filmToCreate.Genres = new List <FilmWithGenre>(); FilmWithGenre fwg = new FilmWithGenre() { GenreId = model.MainGenreID, Genre = await genreLogic.GetAsync(model.MainGenreID).ConfigureAwait(false), Film = filmToCreate, }; filmToCreate.Genres.Add(fwg); var film = await filmLogic.CreateAsync(filmToCreate).ConfigureAwait(false); return(Ok(new FilmDTO(film))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> PutAsync(Guid id, [FromBody] FilmDTO model) { await Task.Yield(); try { var originalFilm = await filmLogic.GetAsync(id).ConfigureAwait(false); model.Id = originalFilm.Id; var updatedFilm = model.ToEntity(); updatedFilm.Director = await directorLogic.GetAsync(model.DirectorID).ConfigureAwait(false); var modifiedEntity = await filmLogic.UpdateAsync(updatedFilm, originalFilm); return(Ok(new FilmDTO(modifiedEntity))); } catch (Exception e) { return(BadRequest(e.Message)); } }