public async Task <IHttpActionResult> PostAvtaler(Avtaler avtaler) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Avtalers.Add(avtaler); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (AvtalerExists(avtaler.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = avtaler.Id }, avtaler)); }
public async Task <IHttpActionResult> PutAvtaler(Guid id, Avtaler avtaler) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != avtaler.Id) { return(BadRequest()); } db.Entry(avtaler).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AvtalerExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetAvtaler(Guid id) { Avtaler avtaler = await db.Avtalers.FindAsync(id); if (avtaler == null) { return(NotFound()); } return(Ok(avtaler)); }
public async Task <IHttpActionResult> DeleteAvtaler(Guid id) { Avtaler avtaler = await db.Avtalers.FindAsync(id); if (avtaler == null) { return(NotFound()); } db.Avtalers.Remove(avtaler); await db.SaveChangesAsync(); return(Ok(avtaler)); }