public HttpResponseMessage Post([FromBody] ksiazka pozycja) { using (bibliotekaEntities encje = new bibliotekaEntities()) { encje.ksiazka.Add(pozycja); encje.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created)); } }
public HttpResponseMessage Put(int id, [FromBody] ksiazka pozycja) { using (bibliotekaEntities encje = new bibliotekaEntities()) { var stara = encje.ksiazka.FirstOrDefault(e => e.id == id); if (stara != null) { stara.autor = pozycja.autor; stara.tytul = pozycja.tytul; stara.rok_wydania = pozycja.rok_wydania; encje.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, pozycja)); } return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Książka o numerze " + id.ToString() + " nie istnieje.")); } }