public ActionResult InsertQuestionPage(FormCollection collection)
        {
            StringBuilder    sbResult = new StringBuilder();
            AskResult        result   = new AskResult();
            List <AskAnswer> answers  = new List <AskAnswer>();

            string TopicName = collection["topicname"];

            foreach (string key in collection.Keys)
            {
                if (key.IndexOf("iptquestion") >= 0)
                {
                    if (sbResult.Length > 0)
                    {
                        sbResult.Append(",");
                    }
                    sbResult.AppendFormat("{0}:{1}", key, collection[key]);
                    int    aIndex        = key.LastIndexOf("a");
                    string stringTopicId = "";
                    if (aIndex >= 0)
                    {
                        stringTopicId = key.Substring(aIndex + 1);
                    }
                    int topicId = 0;
                    int.TryParse(stringTopicId, out topicId);

                    answers.Add(new AskAnswer()
                    {
                        SelectResult = collection[key], TopicId = topicId, Score = PageHelper.GetQuestionScore(collection[key])
                    });
                }
            }

            int pid = 0;

            int.TryParse(collection["pageid"], out pid);
            result.pageid     = pid;
            result.createdate = DateTime.Now;

            int uid = 0;

            int.TryParse(collection["uid"], out uid);
            result.uid = uid;

            result.uname     = PageHelper.ClientIP;
            result.pagetitle = TopicName;
            result.score     = answers.Select(a => a.Score).Sum();

            result.answer     = answers.Sum(a => a.Score).ToString();
            result.AnswerJson = new JavaScriptSerializer().Serialize(answers);

            result.answerHtml = collection["divmaindata"];

            asdb.AskResult.Add(result);
            asdb.SaveChanges();
            //iptquestion
            ViewBag.Result      = result;
            ViewBag.PostSuccess = "true";
            return(View("../AskResult/AskResultList"));
        }
        public JsonResult EditAskTopic(int tid, string desc, string type)
        {
            AskTopic at = db.AskTopic.Find(tid);

            if (at != null)
            {
                at.Type  = type;
                at.Title = desc;
                db.SaveChanges();
            }
            return(Json(at));
        }
Beispiel #3
0
        public JsonResult EditAskContent(int cid, string desc)
        {
            AskContent ac = db.AskContent.Find(cid);

            if (ac != null)
            {
                ac.Desc = desc;
                db.SaveChanges();
            }
            return(Json(ac));
        }