Esempio n. 1
0
 public virtual void AddVote(XsVote vote)
 {
     if (!Votes.Contains(vote))
     {
         vote.Answer = this;
         Votes.Add(vote);
     }
 }
Esempio n. 2
0
 public virtual void AddVote(XsVote vote)
 {
     if (!Votes.Contains(vote))
     {
         vote.Question = this;
         Votes.Add(vote);
     }
 }
        public MockXsQuestionRepository()
        {
            if (null == mockQuestion)
            {
                mockQuestion = new XsQuestion();
                XsUser mockUser = new MockXsUserRepository().GetById(100);

                mockQuestion.ID = IdGenerator.GetNextID(ENTITY_TYPE);
                mockQuestion.CreationDT = DateTime.UtcNow;
                mockQuestion.UpdateDT = DateTime.UtcNow;
                mockQuestion.LastUpdator = "Marius";
                mockQuestion.Title = "What Was Stack Overflow Built With?";
                mockQuestion.Content = "What was Stack Overflow built with? Some even wondered if Stack Overflow was built in Ruby on Rails. I consider that a compliment! This question has been covered in some detail in our podcasts, of course, but I know not everyone has time to listen to a bunch of audio footage to find the answer to their question. So, in that spirit, here’s the technology “stack” of Stack Overflow, the stuff Jarrod, Geoff, and I used to build it:";

                mockQuestion.Author = mockUser;
                mockQuestion.Status = XsStatus.Published;
                mockQuestion.PublishedDT = DateTime.UtcNow;
                XsTag tag1 = new XsTag();
                tag1.Name = ".NET";
                mockQuestion.AddTag(tag1);

                XsTag tag2 = new XsTag();
                tag2.Name = "MVC";
                mockQuestion.AddTag(tag2);
            }

            if (null == questions)
            {

                questions = new List<XsQuestion>();

                for (int i = 0; i <= 100; i++)
                {
                    XsQuestion question = new XsQuestion();

                    int nextID = IdGenerator.GetNextID(ENTITY_TYPE);
                    question.ID = nextID;

                    question.LastUpdator = "Marius " + String.Format("{000}", nextID);
                    question.Title = "What Was Stack Overflow Built With? " + String.Format("{000}", nextID);
                    question.Content = "What was Stack Overflow built with? Some even wondered if Stack Overflow was built in Ruby on Rails. I consider that a compliment! This question has been covered in some detail in our podcasts, of course, but I know not everyone has time to listen to a bunch of audio footage to find the answer to their question. So, in that spirit, here’s the technology “stack” of Stack Overflow, the stuff Jarrod, Geoff, and I used to build it:";

                    question.Author = new MockXsUserRepository().GetById(nextID);
                    question.Status = XsStatus.Published;
                    question.PublishedDT = DateTime.UtcNow;

                    //tags
                    XsTag tag1 = new XsTag();
                    tag1.Name = ".Net " + String.Format("{000}", nextID);
                    question.AddTag(tag1);

                    XsTag tag2 = new XsTag();
                    tag2.Name = "MVC  " + String.Format("{000}", nextID);
                    question.AddTag(tag2);

                    //votes
                    int numberOfVotes = new Random().Next(5, 20);
                    for (int voteIndex = 0; voteIndex < numberOfVotes; voteIndex++)
                    {
                        XsVote vote = new XsVote();
                        vote.Type = VoteType.UpDown;
                        vote.User = new MockXsUserRepository().GetById(nextID);
                        vote.Value = Convert.ToInt16( voteIndex % 2);
                        question.AddVote(vote);
                    }

                    int numberOfAnswers = new Random().Next(10);
                    for (int answerIndex = 0; answerIndex < numberOfAnswers; answerIndex++)
                    {
                        XsAnswer answer = new XsAnswer();
                        answer.Content = "What do you really want to do? If you want to learn Clojure||ruby||C do that. If you just want to get it done do whatever is fastest for you to do. And at the very least when you say Clojure and library you are also saying Java and library, there are lots and some are very good(I don't know what they are though). And the same was said for ruby and python above. So what do you want to do?";
                        answer.Author = question.Author = new MockXsUserRepository().GetById(nextID);
                        answer.ID = IdGenerator.GetNextID("Answer");

                        question.AddAnswer(answer);
                    }

                    questions.Add(question);
                }
            }
        }
        private Int16 RegisterQuestionVoteUp(long questionID, String username, String voteAction)
        {
            XsQuestion question = questionRepository.GetById(questionID);
            XsVote duplicateVote = null;

            if (null == question)
            {
                String errText = "Question ID " + questionID.ToString() + " does not exist in the DB";
                log.Error(errText);
                throw new Exception(errText);
            }

            if (voteAction.Equals(VOTE_ACTION_RECALL))
            {
                foreach (XsVote vote in question.Votes)
                {
                    if ((vote.Question.ID == questionID)
                        && (vote.User.Username.Equals(username)) && (VOTE_UP_VALUE == vote.Value))
                    {
                        duplicateVote = vote;
                        question.Votes.Remove(duplicateVote);
                        voteRepository.Delete(duplicateVote);
                        break;
                    }
                }
            }
            else
            {
                XsVote vote = new XsVote();
                vote.Type = VoteType.UpDown;
                vote.User = userRepository.GetByUsername(username);
                vote.Value = VOTE_UP_VALUE;

                question.AddVote(vote);
                questionRepository.Save(question);
            }

            return question.TotalVoteValue;
        }
        private short RegisterAnswerVoteDown(long answerID, String username, String voteAction)
        {
            XsAnswer answer = answerRepository.GetById(answerID);

            XsVote duplicateVote = null;

            if (null == answer)
            {
                String errText = "Answer ID " + answerID.ToString() + " does not exist in the DB";
                log.Error(errText);
                throw new Exception(errText);
            }

            if (voteAction.Equals(VOTE_ACTION_RECALL))
            {
                foreach (XsVote vote in answer.Votes)
                {
                    if ((vote.Answer.ID == answerID)
                        && (vote.User.Username.Equals(username)) && (VOTE_DOWN_VALUE == vote.Value))
                    {
                        duplicateVote = vote;
                        answer.Votes.Remove(duplicateVote);
                        voteRepository.Delete(duplicateVote);
                        break;
                    }
                }
            }
            else
            {

                XsVote vote = new XsVote();
                vote.Type = VoteType.UpDown;
                vote.User = userRepository.GetByUsername(username);
                vote.Value = VOTE_DOWN_VALUE;

                answer.AddVote(vote);
                answerRepository.Save(answer);
            }

            return answer.TotalVoteValue;
        }