예제 #1
0
        // PUT api/Location/5
        public async Task<IHttpActionResult> PutLocation(int id, Location location)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
예제 #2
0
        public double CalculateDistance(Location a, Location b)
        {
            var geoA = new GeoCoordinate(a.Latitude, a.Longitude);
            var geoB = new GeoCoordinate(b.Latitude, b.Longitude);

            var distInMeters = geoA.GetDistanceTo(geoB);
            var distInMiles = distInMeters * 0.000621371;

            return distInMiles + 0.001;
        }
예제 #3
0
        public async Task<IHttpActionResult> PostLocation(Location location)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Locations.Add(location);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = location.LocationID }, location);
        }