Ejemplo n.º 1
0
 /// <summary>
 /// Returns whether the <paramref name="ntUsername"/> has a Down Vote for the <paramref name="question"/>
 /// </summary>
 /// <param name="ntUsername"></param>
 /// <param name="question"></param>
 /// <returns></returns>
 public static bool IsUserAnswerDownVote(String ntUsername, XsQuestion question)
 {
     bool userHasDownVote = false;
     foreach (XsVote vote in question.Votes)
     {
         if ((vote.User.Username.Equals(ntUsername)) && (vote.Value == VOTE_DOWN_VALUE))
         {
             userHasDownVote = true;
             break;
         }
     }
     return userHasDownVote;
 }
Ejemplo n.º 2
0
 public virtual void AddQuestion(XsQuestion question)
 {
     Questions.Add(question);
     _questionsCount++;
 }
Ejemplo n.º 3
0
 public virtual void RemoveQuestion(XsQuestion question)
 {
     Questions.Remove(question);
     _questionsCount--;
 }
        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);
                }
            }
        }
 public XsQuestion SaveOrUpdate(XsQuestion entity)
 {
     throw new NotImplementedException();
 }
 public XsQuestion Save(XsQuestion entity)
 {
     if (0 == entity.ID)
     {
         entity.ID = IdGenerator.GetNextID(ENTITY_TYPE); ;
     }
     questions.Add(entity);
     return entity;
 }
 public XsQuestion GetUniqueByExample(XsQuestion exampleInstance, params string[] propertiesToExclude)
 {
     throw new NotImplementedException();
 }
 public IQueryable<XsQuestion> GetByExample(XsQuestion exampleInstance, params string[] propertiesToExclude)
 {
     throw new NotImplementedException();
 }
 public void Delete(XsQuestion entity)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 10
0
        public ActionResult Edit(long id, XsQuestion questionToSave, FormCollection collection)
        {
            try
            {
                questionToSave = questionRepository.GetById(id);

                if (null != questionToSave)
                {
                    questionToSave.RemoveAllTags();

                    questionToSave.Tags = new List<XsTag>();

                    String tags = RemoveExtraSpaces(collection["QuestionTags"].ToString());

                    String[] qTags = tags.Split(' ');

                    foreach (String tag in qTags)
                    {
                        if (!String.IsNullOrEmpty(tag))
                        {
                            String tagInvariantName = tag.ToLowerInvariant();
                            XsTag currentTag = tagRepository.GetTagByName(tagInvariantName);

                            if (null == currentTag)
                            {
                                currentTag = new XsTag();
                                currentTag.Name = tagInvariantName;
                            }
                            questionToSave.AddTag(currentTag);
                        }
                    }

                    questionToSave.Title = collection["Title"].ToString();
                    questionToSave.Content = collection["Content"].ToString();

                    questionToSave.ContentHtml = new Markdown().Transform(questionToSave.Content);
                    questionToSave.Excerpt = Utils.CreateContentExcerpt(questionToSave.ContentHtml);
                    questionToSave.UpdateDT = DateTime.UtcNow;

                    ModelState.AddModelErrors(questionToSave.GetRuleViolations());

                    if (ModelState.IsValid)
                    {
                        try
                        {
                            questionToSave.ToAddToSearchIndex = true;
                            questionRepository.Save(questionToSave);
                            return RedirectToAction("Details", "Questions", new { id = questionToSave.ID, seoName = questionToSave.SlugTitle });
                        }
                        catch (Exception ex)
                        {
                            log.Error("There was an error when saving the question in the DB " + ex.Message + "Inner Exception " + ex.InnerException);
                            ViewData["ErrorMessage"] = "There was an error when saving the question in the DB!";
                            return View("Error");

                        }
                    }
                    else
                    {
                        return View(questionToSave);
                    }
                }
            }
            catch
            {
                return View(questionToSave);
            }

            return View(questionToSave);
        }
Ejemplo n.º 11
0
        public ActionResult Create(XsQuestion questionToCreate, String button, String QuestionTags)
        {
            questionToCreate.CreationDT = DateTime.UtcNow;
            questionToCreate.UpdateDT = DateTime.UtcNow;

            if (button.Equals("SaveDraft"))
            {
                questionToCreate.Status = XsStatus.Draft;
            }
            else
            {
                questionToCreate.Status = XsStatus.Published;
                questionToCreate.PublishedDT = DateTime.UtcNow;
            }

            String tags = RemoveExtraSpaces(QuestionTags);

            String[] qTags = tags.Split(' ');

            foreach (String tag in qTags)
            {
                if (!String.IsNullOrEmpty(tag))
                {
                    String tagInvariantName = tag.ToLowerInvariant();

                    XsTag currentTag = tagRepository.GetTagByName(tagInvariantName);

                    if (null == currentTag)
                    {
                        currentTag = new XsTag();
                        currentTag.Name = tagInvariantName;
                    }
                    questionToCreate.AddTag(currentTag);
                }
            }
            questionToCreate.Content = questionToCreate.Content.Replace("<script", "[script").Replace("</script>", "[/script]");
            questionToCreate.ContentHtml = new Markdown().Transform(questionToCreate.Content);
            questionToCreate.Excerpt = Utils.CreateContentExcerpt(questionToCreate.ContentHtml);

            ModelState.AddModelErrors(questionToCreate.GetRuleViolations());

            if (ModelState.IsValid)
            {
                try
                {
                    //TODO: to add other article attributes
                    XsUser author = userRepository.GetByUsername(User.Identity.Name);

                    if (null == author)
                    {
                        author = new XsUser();
                        author.Username = User.Identity.Name;
                        author.QuestionCount = 1;
                    }
                    author.QuestionCount++;
                    questionToCreate.Author = author;
                    questionRepository.Save(questionToCreate);

                    ViewData["QuestionTitle"] = questionToCreate.Title;
                    return View("Confirm");
                }
                catch (Exception ex)
                {
                    log.Error("There was an error when saving the question in the DB " + ex.Message + "Inner Exception " + ex.InnerException );
                    ViewData["ErrorMessage"] = "There was an error when saving the question in the DB!";
                    return View("Error");

                }
            }
            return View();
        }
Ejemplo n.º 12
0
        //
        // GET: /Questions/Create
        public ActionResult Create()
        {
            XsQuestion question = new XsQuestion();

            return View(question);
        }