public async Task<IHttpActionResult> PutLocation(string id, Location location) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != location.id) { 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); }
//Populates the Location table private void PopulateLocation() { Location va = new Location() { id = "vestagder", name = "Vest-Agder" }; Location ut = new Location() { id = "utlandet", name = "Utlandet" }; Location aa = new Location() { id = "austagder", name = "Aust-Agder" }; Location aker = new Location() { id = "akershus", name = "Akershus" }; Location busk = new Location() { id = "buskerud", name = "Buskerud" }; Location finn = new Location() { id = "finnmark", name = "Finnmark" }; Location hed = new Location() { id = "hedmark", name = "Hedmark" }; Location hord = new Location() { id = "hordaland", name = "Hordaland" }; Location møre = new Location() { id = "møreogromsdal", name = "Møre og Romsdal" }; Location nordl = new Location() { id = "nordland", name = "Nordland" }; Location nordt = new Location() { id = "nordtrøndelag", name = "Nord-Trøndelag" }; Location opp = new Location() { id = "oppland", name = "Oppland" }; Location oslo = new Location() { id = "oslo", name = "Oslo" }; Location roga = new Location() { id = "rogaland", name = "Rogaland" }; Location sogn = new Location() { id = "sognogfjordane", name = "Sogn og Fjordane" }; Location sørt = new Location() { id = "sørtrøndelag", name = "Sør-Trøndelag" }; Location tele = new Location() { id = "telemark", name = "Telemark" }; Location troms = new Location() { id = "troms", name = "Troms" }; Location østf = new Location() { id = "østfold", name = "Østfold" }; Location vestf = new Location() { id = "vestfold", name = "Vestfold" }; Location svalb = new Location() { id = "svalbard", name = "Svalbard" }; db.locations.Add(ut); db.locations.Add(aa); db.locations.Add(va); db.locations.Add(aker); db.locations.Add(busk); db.locations.Add(finn); db.locations.Add(hed); db.locations.Add(hord); db.locations.Add(møre); db.locations.Add(nordl); db.locations.Add(nordt); db.locations.Add(opp); db.locations.Add(oslo); db.locations.Add(roga); db.locations.Add(sogn); db.locations.Add(sørt); db.locations.Add(tele); db.locations.Add(troms); db.locations.Add(vestf); db.locations.Add(østf); db.locations.Add(svalb); db.SaveChanges(); }
public async Task<IHttpActionResult> PostLocation(Location location) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.locations.Add(location); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (LocationExists(location.id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = location.id }, location); }