public IHttpActionResult PutMapRestricted(int id, MapRestricted mapRestricted) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != mapRestricted.Id) { return(BadRequest()); } db.Entry(mapRestricted).State = System.Data.Entity.EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MapRestrictedExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
/* **** * send me a series of uav id's batched and i will return a schedule for each uavid sent. * uav id's must be valid or it will dberror * **** */ // POST api/Schedule/GenerateScheduleForUAV public Schedule GenerateScheduleForUAV(int uavID) { var sched = new Schedule { UAVId = uavID, Maintenances = new List <Maintenance>() { new Maintenance { last_maintenance = DateTime.Now.AddHours(-1.0f), next_maintenance = DateTime.Now.AddHours(5.0f), time_remaining = (DateTime.Now.AddHours(5.0f) - DateTime.Now).ToString(), } }, Missions = new List <Mission>() { new Mission { EstimatedCompletionTime = DateTime.Now.AddHours(0.5f), FinancialCost = (decimal)5, FlightPattern = (string)@"zigzag", Payload = (string)@"500lbs", Priority = 3, ScheduledCompletionTime = DateTime.Now.AddHours(0.7f), TimeAssigned = DateTime.Now.AddHours(-0.1f), TimeCompleted = DateTime.Now, Phase = (string)@"En route", Longitude = -117.861328, Latitude = 34.089061 } }, }; try { db.Schedules.Add(sched); db.SaveChanges(); } catch (DbUpdateException incandescent) { //return null; } return(sched); }
public IHttpActionResult PostCMD_NAV_TARGET(int uid, CMD_NAV_Target jsObject) { CMD_NAV_Target cmd_nav_target = new CMD_NAV_Target(); cmd_nav_target.Id = jsObject.Id; cmd_nav_target.Altitude = jsObject.Altitude; cmd_nav_target.Latitude = jsObject.Latitude; cmd_nav_target.Longitude = jsObject.Longitude; cmd_nav_target.UAVId = jsObject.UAVId; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.CMD_NAV_Target.Add(cmd_nav_target); db.SaveChanges(); return(Ok()); }
public IHttpActionResult assignMultipleUAVs(int user_id, int amt) { IEnumerable <UAV> uavs = db.UAVs.Where(u => u.User == null && u.isActive == true).Take(amt); NEST_App.Models.User user = db.Users.Find(user_id); foreach (UAV uav in uavs) { user.UAVs.Add(uav); } db.Entry(user).State = EntityState.Modified; try { db.SaveChanges(); } catch { return(StatusCode(HttpStatusCode.Conflict)); } return(Ok(user)); }
/** * Returns -1 if the insertion into the database failed. */ public int SendCommand(CMD_NAV_Target target) { using (var db = new NestContainer()) { target = db.CMD_NAV_Target.Add(target); int result = db.SaveChanges(); if (result == 1) { //The target was added, so send the target command to the vehicles. Clients.Group("vehicles").sendTargetCommand(target, Context.ConnectionId); //Return the target ID so they know what the ID is in the database. return(target.Id); } else { //Not added, return, let caller know return(-1); } } }
public DateTime GetEta(int id) { var uav = _db.UAVs.Find(id); var firstOrDefault = uav.Schedules.FirstOrDefault(); if (firstOrDefault == null) { return(new DateTime()); } if (firstOrDefault.CurrentMission == null) { return(new DateTime()); } var currentMissionId = (int)firstOrDefault.CurrentMission; var currentMission = _db.Missions.Find(currentMissionId); var orDefault = uav.FlightStates.FirstOrDefault(); if (orDefault == null) { return(new DateTime()); } var radianVelocity = GeoCodeCalc.CalcPythagorean(orDefault.VelocityX, orDefault.VelocityY); if (currentMission.TimeAssigned == null) { return(new DateTime()); } var flightState = uav.FlightStates.FirstOrDefault(); if (flightState == null) { return(new DateTime()); } currentMission.EstimatedCompletionTime = ((DateTime)currentMission.TimeAssigned).AddMinutes(GeoCodeCalc.CalcDistance(flightState.Latitude, flightState.Longitude, currentMission.Latitude, currentMission.Longitude) / radianVelocity); _db.Entry(currentMission).State = System.Data.Entity.EntityState.Modified; _db.SaveChanges(); return((DateTime)currentMission.EstimatedCompletionTime); }