public void InvalidAnswer1()
        {
            Answer a = new Answer { UserId = 3, QuestionId = 2, Content = "Hello, Im invalid because my content is too short.", Votes = 5 };

            db.Answers.Add(a);
            db.SaveChanges();
        }
        public void InvalidAnswer2()
        {
            Answer a = new Answer { UserId = 1, QuestionId = 3, Flag = 5, Content = "Hello, Here is my fabilous awnser to your somewhat silly question. I've never had problems with this kind of things. I always do the thingy first and afterwards I do the other thingy. Result: Profit. Kthxbai.", Votes = 5 };

            db.Answers.Add(a);
            db.SaveChanges();
        }
        public void DefaultsForNewAnswer()
        {
            Answer a = new Answer();

            // Should not be null
            Assert.IsNotNull(a.Created_At, "Created At should not be null");
            Assert.IsNotNull(a.Flag, "Flag should not be null");
            Assert.IsNotNull(a.Votes, "Votes should not be null");

            // Expected Default values
            Assert.AreEqual(0, a.Flag, "Flag should be initialized to 0");
            Assert.AreEqual(0, a.Votes, "Votes should be initialized to 0");
            Assert.IsTrue(a.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);
        }