public IHttpActionResult PostGeoMaster(GeoMaster geomaster) { if (!ModelState.IsValid) { return BadRequest(ModelState); } //get week var weekId = db.Week.First().Week_Id; //set week to geomaster geomaster.Week = weekId; //get user id and teamname var currentUserId = User.Identity.GetUserId(); var currentTeamName = manager.FindById(currentUserId).TeamName; //set TeamName if (geomaster.TeamName.Length <= 0) { geomaster.TeamName = currentTeamName; } //convert lat long to geomaster location geomaster.Location = DbGeography.FromText("POINT(" + geomaster.Longitude + " " + geomaster.Latitude + ")"); db.GeoMasters.Add(geomaster); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = geomaster.Id }, geomaster); }
// PUT api/GeoMaster/5 public IHttpActionResult PutGeoMaster(int id, GeoMaster geomaster) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != geomaster.Id) { return BadRequest(); } //convert lat long to geomaster location geomaster.Location = DbGeography.FromText("POINT(" + geomaster.Longitude + " " + geomaster.Latitude + ")"); db.Entry(geomaster).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!GeoMasterExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }