Beispiel #1
0
        public ActionResult CreateQuestion(string editorContent, string tagSelect, string stringTitle)
        {
            var appliedTagList = JsonConvert.DeserializeObject<string[]>(tagSelect);
            int ptId = 0;
            if (ModelState.IsValid)
            {
                Question asking = new Question();

                asking.Title = stringTitle;
                while (editorContent.EndsWith("<br>"))
                    editorContent = editorContent.Substring(0, editorContent.Length - 4);
                asking.Content = editorContent.Trim('\r', '\n', ' ');
                //article.UserId =  User.Identity.GetUserId<int>();
                asking.UserId =  User.Identity.GetUserId<int>();
                asking.CreateDate = DateTime.Now;
                asking.isActive = true;
                //asking. = 0;

                db.Questions.Add(asking);
                db.SaveChanges();
                ptId = asking.Id;
                if (appliedTagList != null)
                {
                    foreach (var item in appliedTagList)
                    {
                        AppliedTagQuestion appliedTag = new AppliedTagQuestion();
                        appliedTag.QuestionId = asking.Id;
                        appliedTag.TagId = Int32.Parse(item);
                        //appliedTag.TaggingUser =  User.Identity.GetUserId<int>();
                        appliedTag.AppliedDate = DateTime.Now;
                        db.AppliedTagQuestions.Add(appliedTag);
                        db.SaveChanges();
                    }
                }
            }

            return Json(ptId, JsonRequestBehavior.AllowGet);
        }
Beispiel #2
0
 public ActionResult QuestionSuggest(string title)
 {
     List<Question> results = new List<Question>();
     foreach (var question in db.Questions.Where(q => q.isActive == true && q.Answers.Count > 0))
     {
         if (BreakStringsAndCheck(title.ToLower().ToUnsign(), question.Title.ToLower().ToUnsign()) >= 50)
         {
             Question result = new Question
             {
                 Id = question.Id,
                 Title = question.Title,
                 Content = question.Answers.Count + " câu trả lời, " + question.CreateDate.ToTimeAgo()
             };
             results.Add(result);
         }
     }
     if (results.Count > 0)
     {
         return Json(new { success = true, result = results });
     }
     return Json(new { success = false });
 }