public bool editPost(int id, Post innpost) { try { var org = getPost(id); if (org.mail != innpost.mail) org.mail = innpost.mail; if (org.question != innpost.question) org.question = innpost.question; if (org.category != innpost.category) org.category = innpost.category; if (org.answer != innpost.answer) org.answer = innpost.answer; if (org.answered != innpost.answered) org.answered = innpost.answered; if (org.upvotes != innpost.upvotes) org.upvotes = innpost.upvotes; if (org.downvotes != innpost.downvotes) org.downvotes = innpost.downvotes; db.SaveChanges(); return true; } catch (Exception e) { string msg = "Exception: " + e + " thrown at editPost()!"; return false; } }
public bool savePost(Post innpost) { try { db.Posts.Add(innpost); db.SaveChanges(); return true; } catch(Exception e) { string msg = "Exception: " + e + " thrown at savePost()!"; return false; } }
// POST api/FAQ public HttpResponseMessage Post(Post innpost) { if (ModelState.IsValid) { if (db.savePost(innpost)) { return new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; } } return new HttpResponseMessage() { StatusCode = HttpStatusCode.NotFound, Content = new StringContent("Could not save post!") }; }