public brukerSprsml hentEtBrukerSprsml(int id) { BrukerSprsml etBrukerSprsml = db.BrukerSprsml.Find(id); var etSprsml = new brukerSprsml() { id = etBrukerSprsml.id, sprsml = etBrukerSprsml.sprsml, email = etBrukerSprsml.email }; return(etSprsml); }
// GET api/Kunde/5 public HttpResponseMessage Get(int id) { brukerSprsml etBrukerSprsml = brukerSprsmlDb.hentEtBrukerSprsml(id); var Json = new JavaScriptSerializer(); string JsonString = Json.Serialize(etBrukerSprsml); return(new HttpResponseMessage() { Content = new StringContent(JsonString, Encoding.UTF8, "application/json"), StatusCode = HttpStatusCode.OK }); }
public bool lagreEtBrukerSprsml(brukerSprsml innSprsml) { var nyttSprsml = new BrukerSprsml { sprsml = innSprsml.sprsml, email = innSprsml.email, }; try { db.BrukerSprsml.Add(nyttSprsml); db.SaveChanges(); } catch (Exception feil) { return(false); } return(true); }
// PUT api/Kunde/5 public HttpResponseMessage Put(int id, [FromBody] brukerSprsml innSprsml) { if (ModelState.IsValid) { bool OK = brukerSprsmlDb.endreEtBrukerSprsml(id, innSprsml); if (OK) { return(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }); } } return(new HttpResponseMessage() { StatusCode = HttpStatusCode.NotFound, Content = new StringContent("Kunne ikke endre spørsmålet i DB") }); }
public HttpResponseMessage Post([FromBody] brukerSprsml innSprsml) { if (ModelState.IsValid) { bool OK = brukerSprsmlDb.lagreEtBrukerSprsml(innSprsml); if (OK) { return(new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }); } } return(new HttpResponseMessage() { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("Kunne ikke sette inn spørsmål i DB") }); }
public bool endreEtBrukerSprsml(int id, brukerSprsml innSprsml) { BrukerSprsml funnetSprsml = db.BrukerSprsml.FirstOrDefault(q => q.id == id); if (funnetSprsml == null) { return(false); } funnetSprsml.sprsml = innSprsml.sprsml; funnetSprsml.email = innSprsml.email; try { db.SaveChanges(); } catch (Exception feil) { return(false); } return(true); }