public GpsContext GetContext(bool newInstance = false) { if (context == null || newInstance == true) { var options = new DbContextOptionsBuilder <GpsContext>() .UseInMemoryDatabase(databaseName: "TestDb") .Options; GpsContext gpsContext = new GpsContext(options); gpsContext.Database.EnsureDeleted(); //Make sure that data will be deleted List <Locations> locations = LocationsListStub.GetLocationsList(); gpsContext.Locations.AddRange(locations); List <Trackers> trackers = TrackersListStub.GetTrackersList(); gpsContext.Trackers.AddRange(trackers); List <Transports> transports = TransportListStub.GetTransportList(); gpsContext.Transports.AddRange(transports); List <Orders> orders = OrdersListStub.GetOrdersList(); gpsContext.Orders.AddRange(orders); Users user = UserStub.GetUser(); gpsContext.Users.Add(user); gpsContext.SaveChanges(); context = gpsContext; } return(context); }
public ActionResult <Gps> PostGpsItem(Gps gps) { System.Console.WriteLine(gps); if (ModelState.IsValid) { System.Console.WriteLine(gps); gps.createdAt = DateTime.Now; gps.updatedAt = DateTime.Now; _context.GpsItems.Add(gps); _context.SaveChanges(); return(CreatedAtAction("GetGpsItem", new Gps { id = gps.id }, gps)); } return(BadRequest()); }