// PUT api/GeoResult/5 public IHttpActionResult PutGeoResult(int id, GeoResult georesult) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != georesult.Id) { return BadRequest(); } db.Entry(georesult).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!GeoResultExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostGeoResult(GeoResult georesult) { if (!ModelState.IsValid) { return BadRequest(ModelState); } //Get user ID //------------------------------------ var currentUserId = User.Identity.GetUserId(); var currentTeamName = manager.FindById(currentUserId).TeamName; //Set user information so we dont have to send it from javascript. Seems like a hacker could hack the guid being sent through ajax. //------------------------------------ georesult.TeamName = currentTeamName; georesult.UserId = currentUserId; georesult.Location = DbGeography.FromText("POINT(" + georesult.Longitude + " " + georesult.Latitude + ")"); //Get Current Week //------------------------------------ var weekId = db.Week.First().Week_Id; //Get GeoMaster by week //---------------------- var geoMasters = db.GeoMasters.Where(x => x.Week == weekId).FirstOrDefault(); //Get distance between the posted users bullshit guess, and then the real answer //---------------------- var distance = georesult.Location.Distance(geoMasters.Location); distance = distance * 0.000621371; decimal distaanceAway = (decimal)(distance); distaanceAway = Math.Round(distaanceAway, 3); //Add the distance to the geoResult model //---------------------- georesult.DistanceAway = distaanceAway; db.GeoResults.Add(georesult); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = georesult.Id }, georesult); }