Exemple #1
0
        public ActionResult submitQuestion(String title, String category, String questiontext)
        {
            String fileLocation = "";
            String picname      = "";

            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase file = Request.Files[0];
                if (file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    fileLocation = Path.Combine(
                        Server.MapPath("~/"), fileName);
                    file.SaveAs(fileLocation);
                }
            }
            if (fileLocation == "")
            {
                picname = "defaultPic.jpg";
            }
            else
            {
                picname = Request.Files[0].FileName;
            }
            DateTime           dt = DateTime.Now;
            QuestionCategories databasecategory = db.categories.ToList().Find(x => x.Category == category);
            Question           q = new Question {
                Title = title, Text = questiontext, Picture = picname, Category = databasecategory, Status = 1, Author = (User)Session["user"], CreationTime = dt
            };

            db.questions.Add(q);
            db.SaveChanges();
            return(Redirect("Index"));
        }
        public ActionResult Create(QuestionCategories questionCat)
        {
            try
            {
                var question = questionCat.Question;

                using (QuestionAnswerContext context = new QuestionAnswerContext())
                {
                    question.Category = context.Categories.Find(question.Category.Id);
                    question.User     = context.Users.Find(1);

                    question.CreationDate = DateTime.Now;

                    question.AnswerCount = 0;
                    question.ViewCount   = 0;
                    question.Votes       = null;

                    context.Questions.Add(question);
                    context.SaveChanges();

                    return(RedirectToAction("Questions", "Home", null));
                }
            }
            catch
            {
                using (QuestionAnswerContext context = new QuestionAnswerContext())
                {
                    var categories        = context.Categories.ToList();
                    QuestionCategories qc = new QuestionCategories();
                    qc.Categories = categories;
                    return(View(qc));
                }
            }
        }
        public void removeCategory(String dataValue)
        {
            QuestionCategories qc = db.categories.ToList().Find(x => x.Category == dataValue);

            foreach (var question in db.questions.ToList())
            {
                if (question.Category == qc)
                {
                    foreach (var replies in db.replies.ToList())
                    {
                        if (replies.ReplyToWhichQuestion == question)
                        {
                            foreach (var grade in db.grades.ToList())
                            {
                                if (grade.ReplyId == replies.Id)
                                {
                                    db.grades.Remove(grade);
                                }
                            }
                            db.replies.Remove(replies);
                        }
                    }
                    db.questions.Remove(question);
                }
            }
            db.categories.Remove(qc);
            db.SaveChanges();
        }
        public QuestionnaireTemplate GetQuestionnaireTemplate(int questionnaireTemplateId, string locale,
                                                              out GenericError error, DateTime now, int userId)
        {
            error = null;


            try
            {
                if (_serviceTemplate == null)
                {
                    _serviceTemplate = new Lazy <QuestionnaireTemplate>(() =>
                    {
                        var serviceTemplate = new QuestionnaireTemplate();
                        Model.Questionnaire.QuestionnaireTemplate questionTemplate =
                            _questionnaireBuilder.BuildQuestionnaireTemplate();

                        var categoryRes = new QuestionCategories();

                        questionTemplate.QuestionCategories.ForEach(c => FillServiceCategory(locale, categoryRes, c));

                        serviceTemplate.QuestionCategories = categoryRes.QuestionCategoriesList;
                        return(serviceTemplate);
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.Controller.LogError(ex);
                error = ErrorClasses.Controller.GetUnknownError();
                return(null);
            }
            FillDailyInfoSpecificDisplayQuestions(userId, _serviceTemplate.Value, now);

            return(FillCategoryGeneralDescriptions(_serviceTemplate.Value));
        }
        public void addCategory(String dataValue)
        {
            QuestionCategories qc = new QuestionCategories {
                Category = dataValue
            };

            db.categories.Add(qc);
            db.SaveChanges();
        }
Exemple #6
0
 public void ReplaceCategories(IEnumerable <int> categoryIds)
 {
     QuestionCategories.Clear();
     foreach (var categoryId in categoryIds)
     {
         QuestionCategories.Add(new QuestionCategory {
             CategoryId = categoryId
         });
     }
 }
 public ActionResult Create()
 {
     using (QuestionAnswerContext context = new QuestionAnswerContext())
     {
         var categories        = context.Categories.ToList();
         QuestionCategories qc = new QuestionCategories();
         qc.Categories = categories;
         return(View(qc));
     }
 }
        private void LocalizeServiceCategory(string locale, QuestionCategories categoryRes, QuestionCategory c)
        {
            var questionsRes = new Questions();

            c.Questions.ForEach(q => LocalizeServiceQuestion(locale, questionsRes, q));

            ServiceModel.Questionnaire.QuestionCategory serviceCategory = categoryRes.AddItem(locale,
                                                                                              c.CategoryQuestion
                                                                                              .Description,
                                                                                              c.CategoryQuestion.Help);
            serviceCategory.CategoryQuestion = LocalizeServiceCategoryQuestion(locale, c);
            serviceCategory.Questions        = questionsRes.QuestionsList;
        }
        public virtual ServiceModel.Questionnaire.QuestionnaireTemplate LocalizeTemplate(QuestionnaireTemplate questionTemplate)
        {
            var serviceTemplate = new ServiceModel.Questionnaire.QuestionnaireTemplate {
                TemplateId = TemplateId
            };

            var categoryRes = new QuestionCategories();

            questionTemplate.QuestionCategories.ForEach(c => LocalizeServiceCategory(TemplateLocaleName, categoryRes, c));

            serviceTemplate.QuestionCategories = categoryRes.QuestionCategoriesList;


            return(serviceTemplate);
        }
Exemple #10
0
        public static List <QuizQuestion> LoadQuestionCategory(QuestionCategories category)
        {
            switch (category)
            {
            case QuestionCategories.general_knowledge:
                return(LoadQuestions(category, "generalKnowledge.txt"));

            case QuestionCategories.math_science:
                return(LoadQuestions(category, "mathAndScience.txt"));

            case QuestionCategories.sports:
                return(LoadQuestions(category, "sports.txt"));

            case QuestionCategories.entertainment:
                return(LoadQuestions(category, "entertainment.txt"));

            default:
                throw new ArgumentException("Invalid question category!");
            }
        }
Exemple #11
0
        private static List <QuizQuestion> LoadQuestions(QuestionCategories category, string filePath)
        {
            List <QuizQuestion> questions = new List <QuizQuestion>();

            using (StreamReader questionLoader = new StreamReader(filePath, true))
            {
                while (!questionLoader.EndOfStream)
                {
                    string[] questionInfo = questionLoader.ReadLine().Split('~').ToArray();
                    questions.Add(new QuizQuestion()
                    {
                        Category              = category,
                        Question              = questionInfo[0],
                        CorrectAnswer         = questionInfo[1],
                        FirstIncorrectAnswer  = questionInfo[2],
                        SecondIncorrectAnswer = questionInfo[3],
                    });
                }
            }

            return(questions);
        }
 /// <summary>
 /// Sets a question category from main menu
 /// </summary>
 /// <param name="category"></param>
 public void SetCategory(QuestionCategories category)
 {
     this.category = category;
 }
Exemple #13
0
 public void ShowQuestionCategory(QuestionCategories questionCategories)
 {
     _writer.WriteLine($"The category is {questionCategories}");
 }