public async Task <IActionResult> PutFilmGenre(int id, FilmGenre filmGenre) { if (id != filmGenre.Id) { return(BadRequest()); } FilmGenreValid c = new FilmGenreValid(_context, filmGenre); if (!c.Valid()) { return(BadRequest("Фільм з таким жанром уже існує")); } _context.Entry(filmGenre).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FilmGenreExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <FilmGenre> > PostFilmGenre(FilmGenre filmGenre) { _context.FilmGenre.Add(filmGenre); FilmGenreValid c = new FilmGenreValid(_context, filmGenre); if (!c.Valid()) { return(BadRequest("Фільм з таким жанром уже існує")); } await _context.SaveChangesAsync(); return(CreatedAtAction("GetFilmGenre", new { id = filmGenre.Id }, filmGenre)); }