public void UpdatePost(Post InnPost) { using (var db = new FaqContext()) { Posts post = (from p in db.Posts where p.PostId == InnPost.PostId select p).First(); if (InnPost.Votes == 1) { post.Votes = post.Votes + 1; db.SaveChanges(); } else { post.Answer = InnPost.Answer; post.TimeStamp = DateTime.Now.ToString(); post.IsAnswered = true; db.SaveChanges(); } } }
public void AddPost(Post NewPost) { Debug.WriteLine(NewPost.Category); try { using (var db = new FaqContext()) { var NewPostRow = new Posts(); NewPostRow.PostId = NewPost.PostId; NewPostRow.Question = NewPost.Question; NewPostRow.Answer = NewPost.Answer; if(NewPost.Category == null){ NewPostRow.Category = "Other";} else NewPostRow.Category = NewPost.Category; NewPostRow.UserEmail = NewPost.UserEmail; NewPostRow.TimeStamp = DateTime.Now.ToString(); NewPostRow.IsAnswered = false; db.Posts.Add(NewPostRow); db.SaveChanges(); } } catch(Exception e) { Debug.WriteLine("klikker her"); Debug.WriteLine(e.ToString()); } }
public void Put(Post post) { db.UpdatePost(post); }
public void Post(Post post) { db.AddPost(post); }