public IHttpActionResult PutTripLocation(long id, TripLocation tripLocation)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Esempio n. 2
0
 public void Seed()
 {
     // TripLocation data
     TripLocation tl = new TripLocation();
     //tl.Id = 1;
     tl.Longitude = System.Convert.ToDecimal(-36.9355829);
     tl.Latitude = System.Convert.ToDecimal(174.6426804);
     tl.InsertDate = System.DateTime.Now;
 }
        private TripLocation Trip()
        {
            TripLocation tl = new TripLocation();
            tl.Longitude = System.Convert.ToDecimal(-36.9355829);
            tl.Latitude = System.Convert.ToDecimal(174.6426804);
            tl.InsertDate = System.DateTime.Now;

            return tl;
        }
        public IHttpActionResult PostTripLocation(TripLocation tripLocation)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.TripLocations.Add(tripLocation);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = tripLocation.Id }, tripLocation);
        }
        private static async Task RunAsync()
        {
            //TODO: sort this!
            TripLocation tl = new TripLocation();
            tl.Longitude = System.Convert.ToDecimal(-36.9355829);
            tl.Latitude = System.Convert.ToDecimal(174.6426804);
            tl.InsertDate = System.DateTime.Now;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost");
                HttpResponseMessage response = await client.PostAsJsonAsync("wheresmydaddy/api/TripLocations", tl);
            }
        }