Beispiel #1
0
        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();
                }

            }
        }
Beispiel #2
0
        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());

            }
        }
Beispiel #3
0
        public List<Post> GetAllPosts()
        {
            using (var db = new FaqContext())
            {
                var AllPosts = db.Posts.ToList().Select(p => new Post
                {
                    PostId = p.PostId,
                    Question = p.Question,
                    Answer = p.Answer,
                    TimeStamp = p.TimeStamp,
                    UserEmail = p.UserEmail,
                    IsAnswered = p.IsAnswered,
                    Category = p.Category,
                    Votes = p.Votes
                }).ToList();

                return AllPosts;
            }
        }