public IHttpActionResult PutNoFlyZone(int id, NoFlyZone noFlyZone)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != noFlyZone.ID)
            {
                return(BadRequest());
            }

            db.Entry(noFlyZone).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NoFlyZoneExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        private void LoadNoFlyZones(DroneDb context)
        {
            context.Configuration.AutoDetectChangesEnabled = false;

            var resourceName = "DroneCrush.Models.SeedData.noFlyZones.txt";
            var assembly     = Assembly.GetExecutingAssembly();
            var stream       = assembly.GetManifestResourceStream(resourceName);

            var line = "";

            // Read the file and display it line by line.
            System.IO.StreamReader fileRead =
                new System.IO.StreamReader(stream);
            while ((line = fileRead.ReadLine()) != null)
            {
                string[] components = line.Split(';');

                string lat      = components[0];
                string lng      = components[1];
                string zoneName = components[2];
                zoneName.Trim();
                string category = components[3];

                NoFlyCategory zoneCategory;
                if (category == "Category A")
                {
                    zoneCategory = NoFlyCategory.A;
                }
                else
                {
                    zoneCategory = NoFlyCategory.B;
                }

                Coordinate coords = new Coordinate();
                coords.Latitude  = Double.Parse(lat);
                coords.Longitude = Double.Parse(lng);

                context.NoFlyZones.Add(new NoFlyZone {
                    Coordinate = coords, NoFlyZoneName = zoneName, NoFlyCategory = zoneCategory
                });
            }

            fileRead.Close();
            context.SaveChanges();
        }
Example #3
0
        protected override void Seed(DroneDb context)
        {
            LoadNoFlyZones(context);

            context.Drone.Add(new Drone()
            {
                ID          = 1,
                DeviceToken = "esfads",
                Coordinate  = new Coordinate()
                {
                    Latitude  = 42.2312,
                    Longitude = 41.3433
                },
                LastActive = DateTime.Now
            });

            context.SaveChanges();
        }
        private void LoadDummyDrones(DroneDb context)
        {
            var drones = new List <Drone>
            {
                new Drone
                {
                    DeviceToken = "Drone1",
                    LastActive  = DateTime.Now,
                    Name        = "Drone 2",
                    Coordinate  = new Coordinate()
                    {
                        Latitude  = 41.993739,
                        Longitude = 21.4359526
                    },
                },
                new Drone
                {
                    DeviceToken = "Drone2",
                    LastActive  = DateTime.Now,
                    Name        = "Drone 2",
                    Coordinate  = new Coordinate()
                    {
                        Latitude  = 41.9969603,
                        Longitude = 21.4211897
                    }
                },
                new Drone
                {
                    DeviceToken = "Drone3",
                    LastActive  = DateTime.Now,
                    Name        = "Drone 3",
                    Coordinate  = new Coordinate()
                    {
                        Latitude  = 41.9969603,
                        Longitude = 21.4211897
                    }
                },
                new Drone
                {
                    DeviceToken = "Drone4",
                    LastActive  = DateTime.Now,
                    Name        = "Drone 4",
                    Coordinate  = new Coordinate()
                    {
                        Latitude  = 42.0047346,
                        Longitude = 21.4124362
                    }
                },
                new Drone
                {
                    DeviceToken = "Drone5",
                    LastActive  = DateTime.Now,
                    Name        = "Drone 5",
                    Coordinate  = new Coordinate()
                    {
                        Latitude  = 42.0648949,
                        Longitude = 21.2218569
                    }
                }
            };

            drones.ForEach(d => context.Drone.AddOrUpdate(c => c.DeviceToken, d));
            context.SaveChanges();
        }