Beispiel #1
0
 public HttpResponseMessage updateQuestion(GetQuestionModel getquestionMode)
 {
     try
     {
         MessageModel value = new MessageModel();
         value = authenticationUser(getquestionMode.authenticationUser);
         if (value.idMessage == (int)MessageCode.OkUser)
         {
             var q = context.Questions.Where(i => i.id == getquestionMode.question.id).FirstOrDefault();
             q.question = getquestionMode.question.question;
             q.active   = getquestionMode.question.active;
             context.SaveChanges();
             var message = Request.CreateResponse(HttpStatusCode.OK, (int)MessageCode.Savedata);
             return(message);
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.OK, value.idMessage.ToString()));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.OK, ex));
     }
 }
Beispiel #2
0
 public HttpResponseMessage setQuestion(GetQuestionModel getQuestionMode)
 {
     try
     {
         MessageModel value = new MessageModel();
         value = authenticationUser(getQuestionMode.authenticationUser);
         if (value.idMessage == (int)MessageCode.OkUser)
         {
             Questions q = new Questions();
             q.question = getQuestionMode.question.question;
             q.active   = "t";
             context.Questions.Add(q);
             context.SaveChanges();
             var message = Request.CreateResponse(HttpStatusCode.OK, (int)MessageCode.Savedata);
             return(message);
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.OK, value.idMessage.ToString()));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateResponse(HttpStatusCode.OK, ex));
     }
 }
        public ActionResult <List <QuestionModel> > GetQuestions([FromBody] GetQuestionModel questionsModel)
        {
            var questions = learningHubMicroservice.GetQuestions(questionsModel.UserId, questionsModel.Type);

            var result = new List <QuestionModel>();

            foreach (var item in questions)
            {
                result.Add((QuestionModel) new QuestionModel().InjectFrom(item));
            }
            return(result);
        }
        /// <summary>
        /// Returns the details for a question
        /// </summary>
        /// <param name="questionid">Question ID</param>
        /// <returns></returns>
        public ActionResult GetQuestion(int id)
        {
            var actQues = QuestionManager.GetQuestion(id);
            var model   = new GetQuestionModel();

            model.CurrentQuestion = actQues;

            //Get the vote of the question
            model.Vote = QuestionManager.GetVote(model.CurrentQuestion.Id);
            //List the tags of the question
            model.QuestionTags = TagManager.GetAllTagToOneQuestion(id);

            model.QuestionUser = UserManager.GetUserById(model.CurrentQuestion.UserId);



            return(View(model));
        }
Beispiel #5
0
        public static List <GetQuestionModel> ToGetQuestionModels(IEnumerable <Question> questions, int userid)
        {
            //Create a list with the answered questions
            var answeredquestions = new List <GetQuestionModel>();

            foreach (var item in questions)
            {
                var actansweredquestion = new GetQuestionModel();
                //Add the current question to the model
                actansweredquestion.CurrentQuestion = item;
                //Add the answers by the user of the current question to the model
                actansweredquestion.Answers = AnswerManager.GetAllAnswerToOneQuestionFromOneUser(item.Id, userid);
                //Add the vote of current question to the model
                actansweredquestion.Vote = QuestionManager.GetVote(item.Id);
                //Add the tags of the current question to the model
                actansweredquestion.QuestionTags = TagManager.GetAllTagToOneQuestion(item.Id);

                actansweredquestion.AllAnswersNumber = AnswerManager.GetAllAnswerNumberToOneQuestion(item.Id);

                //Create a dictionary for the answers and the votes of them
                actansweredquestion.AnswerVotes = new Dictionary <Answer, int>();

                //Upload the dictionary with the votes
                foreach (var answer in actansweredquestion.Answers)
                {
                    actansweredquestion.AnswerVotes.Add(answer, AnswerManager.GetVote(answer.Id));
                }

                //Add the author of the question to the model
                actansweredquestion.QuestionUser = UserManager.GetUserById(item.UserId);

                //Sort the answers by the votes of them
                actansweredquestion.Answers = actansweredquestion.Answers.OrderByDescending(d => actansweredquestion.AnswerVotes[d]).ToList();

                //Add this QuestionModel to the list
                answeredquestions.Add(actansweredquestion);
            }

            return(answeredquestions);
        }
        public void AddAnswer(GetQuestionModel data, string questionID)
        {
            //Id of the actual question
            int actid       = Int32.Parse(questionID);
            int userid      = 0;
            var model_state = ModelState.IsValid;

            if (Request.IsAuthenticated)
            {
                userid = WebSecurity.CurrentUserId;
            }
            else
            {
                model_state = false;
            }
            if (model_state)
            {
                AnswerManager.AddAnswer(data.ActualAnswer, actid, userid);
            }

            return;
        }
Beispiel #7
0
        /// <summary>
        /// 保存问卷内容
        /// </summary>
        /// <param name="quesId">问卷Id</param>
        /// <param name="message">处理结果信息</param>
        /// <returns></returns>
        private QssResult QssCreateQuesContent(Question question, out string message)
        {
            // 存放转换过得题目和题目选项
            var subjects = new List <GetQuesSubject>();

            // 获取所有题目
            foreach (var subject in question.QuesSubjects)
            {
                var getQuesSubject = new GetQuesSubject();
                // 获取该题目的所有选项
                var quesOptions = subject.QuesOptions;
                if (subject.Type != QssQuesSubType.Subjective)
                {
                    // 非主观题选项
                    var options = new List <GetQuesOption>();
                    foreach (var option in quesOptions)
                    {
                        GetQuesOption getQuesOption = new GetQuesOption
                        {
                            Id      = option.Id,
                            Content = option.Content
                        };

                        options.Add(getQuesOption);
                    }
                    getQuesSubject.Num     = quesOptions.Count();
                    getQuesSubject.Options = options.OrderByDescending(p => p.Id).ToArray();
                }

                // 题目信息
                getQuesSubject.Id      = subject.Id;
                getQuesSubject.Type    = subject.Type.ToString();
                getQuesSubject.Content = subject.Content;

                subjects.Add(getQuesSubject);
            }

            // 问卷内容
            GetQuestionModel questionModel = new GetQuestionModel
            {
                // 全局信息
                Global = new GetQuesGlobal
                {
                    BeginTime        = question.BeginTime,
                    BelongTo         = question.BelongTo,
                    EndTime          = question.EndTime,
                    Id               = question.Id,
                    Introduct        = question.Introduct,
                    IsBelongOrganize = question.IsBelongOrganize,
                    Title            = question.Title,
                    Num              = subjects.Count(),
                    Publisher        = question.Publisher
                },
                // 题目
                Subjects = subjects.OrderByDescending(p => p.Id).ToArray()
            };

            // 保存
            try
            {
                question.Content = JsonConvert.SerializeObject(questionModel);
                CurrentDal.Update(question);
                DbSession.SaveChanges();

                // 保存成功
                message = "成功问卷内容成功!";
                return(QssResult.Success);
            }
            catch (Exception exception)
            {
                // 保存失败
                message = $"保存问卷内容失败!原因:{exception.Message}";
                QssLogHelper.Log("保存问卷内容失败", $"在创建问卷成功之后,保存问卷内容失败! 原因:{exception.Message}", QssLogType.Error);
                return(QssResult.Fail);
            }
        }