public async Task <IActionResult> PutCinemaChain(int id, CinemaChain cinemaChain) { if (id != cinemaChain.Id) { return(BadRequest()); } _context.Entry(cinemaChain).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CinemaChainExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <CinemaChain> > PostCinemaChain(CinemaChain cinemaChain) { _context.CinemaChains.Add(cinemaChain); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCinemaChain", new { id = cinemaChain.Id }, cinemaChain)); }
public async Task <ActionResult <CinemaChain> > PostCinemaChain(CinemaChain cinemaChain) { if (CinemaChainExists(cinemaChain.Id)) { return(Conflict()); } else if (IsDeleted(cinemaChain.Id)) { _context.Entry(cinemaChain).State = EntityState.Modified; var cinemasInDB = _context.Cinemas.Where(c => c.CinemaChainId == cinemaChain.Id).Select(c => c.Id).ToList(); cinemaChain.Cinemas.ToList().ForEach(cinema => { if (cinemasInDB.Contains(cinema.Id)) { _context.Entry(cinema).State = EntityState.Modified; } else { _context.Cinemas.Add(cinema); } }); } else { _context.CinemaChains.Add(cinemaChain); } await _context.SaveChangesAsync(); return(NoContent()); }