public async Task <IActionResult> PutFlight([FromRoute] int id, [FromBody] Flight flight) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != flight.FlightId) { return(BadRequest()); } _context.Entry(flight).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FlightExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Delete(TEntity entityToDelete) { if (Context.Entry(entityToDelete).State == EntityState.Detached) { DbSet.Attach(entityToDelete); } DbSet.Remove(entityToDelete); }
public override void TestInitialize() { base.TestInitialize(); var options = new DbContextOptionsBuilder <AirportDbContext>() .UseInMemoryDatabase("TestDb") .Options; var c = new AirportDbContext(options); obj = new TestClass(c, c.Airports); count = GetRandom.UInt8(20, 40); foreach (var p in c.Airports) { c.Entry(p).State = EntityState.Deleted; } AddItems(); }