Пример #1
0
        public async Task<IHttpActionResult> PutMission(int id, Mission mission)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            db.Entry(mission).State = System.Data.Entity.EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MissionExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #2
0
        public async Task<IHttpActionResult> PostMission(Mission mission)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Missions.Add(mission);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = mission.id }, mission);
        }
Пример #3
0
 public async Task<HttpResponseMessage> createMission(int number)
 {
     Random num = new Random();
     var missions = new List<Mission>();
     for (int i = 0; i < number; i++)
     {
         DbGeography p = getDistance();
         var miss = new Mission
         {
             Phase = "standby",
             FlightPattern = "abstract",
             Payload = getPackage(),
             Priority = 1,
             FinancialCost = num.Next(1, 99),
             TimeAssigned = null,
             TimeCompleted = null,
             //DestinationCoordinates = DbGeography.FromText("POINT(-118.52529 34.241670 400)"),  
             Latitude = p.Latitude ?? 34.2420,
             Longitude = p.Longitude ?? -118.5288,
             ScheduledCompletionTime = null,
             EstimatedCompletionTime = null,
             create_date = DateTime.Now,
             modified_date = null
         };
         missions.Add(miss);
     }
     _db.Missions.AddRange(missions);
     try
     {
         await _db.SaveChangesAsync();
     }
     catch (DbUpdateException e)
     {
         System.Diagnostics.Debug.Write(e);
     }
     return Request.CreateResponse(HttpStatusCode.OK);
 }