public IActionResult Post([FromBody] ParkingSpot item) { if (item == null) { return(BadRequest()); } _context.ParkingSpots.Add(item); _context.SaveChanges(); return(CreatedAtRoute("GetParkingSpot", new { id = item.Id }, item)); }
public ParkingSpotController(ParkingSpotContext context) { _context = context; if (_context.ParkingSpots.Count() == 0) { _context.ParkingSpots.Add(new ParkingSpot { Name = "Item1" }); _context.SaveChanges(); } }
public static void Initialize(ParkingSpotContext context) { context.Database.EnsureCreated(); if (context.ParkingSpots.Count() == 0) { context.ParkingSpots.Add(new ParkingSpot { Lat = 10, Long = 10, capacity = 200, usage = 0 }); context.ParkingSpots.Add(new ParkingSpot { Lat = 5, Long = 20, capacity = 100, usage = 0 }); context.SaveChanges(); } }