예제 #1
0
        public async Task<IHttpActionResult> AppendWaypoints(int id, Waypoint[] wps)
        {
            if (wps.Count() == 0)
            {
                return Ok(wps);
            }
            using (var trans = db.Database.BeginTransaction())
            {
                var wp = await getLastWaypoint(id);
                await this.addWaypointsToMission(id, wps);
                wp.NextWaypointId = wps[0].Id;
                db.Entry(wp).State = System.Data.Entity.EntityState.Modified;
                await db.SaveChangesAsync();

                var hub = GlobalHost.ConnectionManager.GetHubContext<VehicleHub>();
                hub.Clients.All.newRouteForMission(id);

                return Ok(wps);
            }
        }
예제 #2
0
        private async Task addWaypointsToMission(int missionId, Waypoint[] wps)
        {

            var wpLast = wps.Last();
            wpLast.MissionId = missionId;
            wpLast = db.Waypoints.Add(wpLast);
            wpLast.IsActive = true;
            await db.SaveChangesAsync();
            for (int i = wps.Count() - 2; i >= 0; i--)
            {
                var curWp = wps.ElementAt(i);
                curWp.NextWaypointId = wpLast.Id;
                curWp.MissionId = missionId;
                curWp.IsActive = true;
                wpLast = db.Waypoints.Add(curWp);
                await db.SaveChangesAsync();
            }
        }
예제 #3
0
        public async Task<IHttpActionResult> NewRouteForMission(int id, Waypoint[] wps)
        {
            using (var trans = db.Database.BeginTransaction())
            {
                Mission mission = await db.Missions.FindAsync(id);
                if (mission == null)
                {
                    return NotFound();
                }
                if (wps == null || wps.Count() < 1)
                {
                    return BadRequest();
                }
                foreach (var wp in mission.Waypoints)
                {
                    wp.IsActive = false;
                    db.Entry(wp).State = System.Data.Entity.EntityState.Modified;
                }
                await db.SaveChangesAsync();
                await this.addWaypointsToMission(id, wps);

                trans.Commit();
                var hub = GlobalHost.ConnectionManager.GetHubContext<VehicleHub>();
                hub.Clients.All.newRouteForMission(mission.id);

                return Ok(wps);
            }
        }