public void Invalidcomment1()
        {
            Comment c = new Comment { UserId = 1, QuestionId = 1, CommentID = 2, Content = "This is a comment on a question" };

            db.Comments.Add(c);
            db.SaveChanges();
        }
        public void Invalidcomment2()
        {
            Comment c = new Comment { UserId = 1, QuestionId = 1, Content = "Too short" };

            db.Comments.Add(c);
            db.SaveChanges();
        }
        public void DefaultsForNewComment()
        {
            Comment c = new Comment();

            //Should not be null
            Assert.IsNotNull(c.Votes, "Votes should not be null");
            Assert.IsNotNull(c.Created_At, "Created_At should not be null");

            //Expected Default Values
            Assert.AreEqual(0, c.Votes, "Votes should be initialized to 0");
            Assert.IsTrue(c.Created_At == StringToDateTime.ToUnixTimeStamp(DateTime.Now), "Created At should be initialized to DateTime.Now.ToString()");
        }
        public ActionResult View(int id, CommentAnswer input)
        {
            // check if we are adding a comment on an asnwer
            if (input.awnserComment != null)
            {
                // add a new awnser comment
                if (!Request.IsAuthenticated) // check if we are logged in
                    ModelState.AddModelError("", "U dient te zijn ingelogd om te reageren.");
                if (ModelState.IsValid)
                {
                    // all valid
                    // get the info of the user that is making a comment
                    var userAwnsering = from user in db.Users
                                        where user.UserName == User.Identity.Name
                                        select user;

                    if (userAwnsering.Count() == 1)
                    {
                        // if this yielded some user we can actually create the new comment
                        Comment awnserComment = new Comment() { AnswerId = input.awnserID, Content = input.awnserComment, UserId = userAwnsering.First().UserID };
                        db.Comments.Add(awnserComment);
                        db.SaveChanges();
                    }
                    // return them to the page where this question is at
                    return RedirectToAction("view", "vraag", id);
                }
            }
            else if (input.questionComment != null) // check if we are adding a comment on a question
            {
                // add a new comment to the question
                // check if we are logged in
                if (!Request.IsAuthenticated)
                    ModelState.AddModelError("", "U dient te zijn ingelogd om te reageren.");
                if (ModelState.IsValid)
                {
                    // all valid then get the info of the user which is writing this comment
                    var userAwnsering = from user in db.Users
                                        where user.UserName == User.Identity.Name
                                        select user;
                    if (userAwnsering.Count() == 1) // check if we could find this user
                    {
                        // add the new comment
                        Comment questionComment = new Comment() { UserId = userAwnsering.First().UserID, QuestionId = id, Content = input.questionComment };
                        db.Comments.Add(questionComment);
                        db.SaveChanges();
                    }
                    // go back to the question we came from
                    return RedirectToAction("view", "vraag", id);
                }
            }
            else if (input.awnser != null) // check if we are giving a new asnwer
            {
                // Add a new awnser
                // check if we are logged in
                if (!Request.IsAuthenticated)
                    ModelState.AddModelError("", "U dient te zijn ingelogd om te reageren.");
                if (ModelState.IsValid)
                {
                    // get the info off the user ansering
                    var userAwnsering = from user in db.Users
                                        where user.UserName == User.Identity.Name
                                        select user;
                    // and about the question
                    var thisQuestion = from questions in db.Questions
                                       where questions.QuestionID == id
                                       select questions;
                    if (userAwnsering.Count() == 1 && thisQuestion.Count() == 1)
                    {
                        // cast the userID to an int to use it again
                        int userID = userAwnsering.First().UserID;
                        // get the usermeta
                        var userAwnseringMeta = (from usermeta in db.UserMeta
                                                where usermeta.UserId == userID
                                                select usermeta).Single();
                        // add one to the amount of answers given
                        userAwnseringMeta.Answers += 1;

                        // get the userID of the person which is giving an asnwer
                        int AwnserUserID = userAwnsering.First().UserID;
                        // mark this question as one which has a new answer
                        thisQuestion.First().Answers += 1;
                        // add the answer
                        Answer questionAwnser = new Answer() { QuestionId = id, UserId = AwnserUserID, Content = input.awnser };
                        db.Answers.Add(questionAwnser);
                        db.SaveChanges();

                        // ###################################
                        //    check if we got a new badge
                        // ###################################
                        if (AnswerBadge.badgeAchieve(AwnserUserID))
                            AnswerBadge.awardBadge(AwnserUserID);
                        if (AnswerCreatorBadge.badgeAchieve(AwnserUserID))
                            AnswerCreatorBadge.awardBadge(AwnserUserID);
                        if (AnswerLordBadge.badgeAchieve(AwnserUserID))
                            AnswerLordBadge.awardBadge(AwnserUserID);
                        // ###################################
                    }
                    // go back to the current question where we got from
                    return RedirectToAction("view", "vraag", id);
                }

            }
            return View(id);
        }