コード例 #1
0
 public ActionResult AddAnswer(Answer model)
 {
     model.answerdate = DateTime.Now;
     model.answerman = Common.CommonClass1.GetUserName();
     model.answermanid = Common.CommonClass1.GetPartyIdCount().ToString();
     model.state = true;
     var temp = ans.Add(model);
     var questionmodel = qs.FindModelList(o => o.Id == model.Qid).FirstOrDefault();
     questionmodel.state = "0";
     qs.UpDate(questionmodel);
     return Json(temp, JsonRequestBehavior.AllowGet);
 }
コード例 #2
0
        public void UpdateQuestion(int Qid)
        {
            try
            {
                var question = qs.FindModel(new object[] { Qid });
                question.typeid = int.Parse(Request.Form["typeid"]);
                question.title = Request.Form["title"];
                question.content = Request.Form["content"];
                var answer = new Answer();
                if (Request.Form.AllKeys.Contains("answercontent"))
                {
                    answer = ans.FindModelList().Where(o => o.Qid == Qid).FirstOrDefault();
                    answer.answercontent = Request.Form["answercontent"];
                }
                ans.UpDate(answer);
                qs.UpDate(question);
            }
            catch (Exception ex)
            {

                Response.Write(ex.Message);
            }
        }
コード例 #3
0
        public ActionResult GetQuestionByPage(int? module = null, string parenttype = null, string childtype = null, int page = 1)
        {
            int pagenumber = 6;//每页6条
            IEnumerable<Question> list = qs.FindModelList().ToList().OrderByDescending(o => o.regdate);

            //if (module != null)
            //{
            //    list = list.Where(o => o.typeid == module);
            //}

            if (parenttype != null)
            {
               // int manid = 1;
                int manid = Common.CommonClass1.GetPartyIdCount();
                switch (parenttype)
                {
                    case "allquestion"://所有收藏
                        list = qs.FindModelList().OrderByDescending(o => o.regdate);
                        break;
                    case "myquestion":
                        list = list.Where(o => o.regmanid == manid).OrderByDescending(o => o.regdate);
                        break;
                    case "collect":
                        list = cs.FindModelList(o => o.personid == manid).GroupBy(o => o.Question).Select(o => o.Key).OrderByDescending(o => o.regdate);
                        break;
                }

            }
            if (childtype != null && parenttype != "collect")
            {
                switch (childtype)
                {
                    case "all":
                        break;
                    case "resolved"://已解决
                        list = list.Where(o => o.state == "0").OrderByDescending(o => o.regdate);
                        break;
                    case "unsolved"://未解决
                        list = list.Where(o => o.state == "1").OrderByDescending(o => o.regdate);
                        break;

                }
            }

            if (module != -1)
            {
                list = list.Where(o => o.typeid == module).OrderByDescending(o => o.regdate);
            }

            var model = new QuestionCountModel();
            model.allcount = list.Count();//总个数

            list = list.Skip((page - 1) * pagenumber).Take(pagenumber).ToList();
            var templist = new List<QuestionPageModel>();
            foreach (var i in list)
            {
                i.Type.Questions.Clear();
                i.Type.Improvereports.Clear();
                var answer = new Answer();
                if (i.Answers.Count!=0)
                {
                    answer = i.Answers.ToList().FirstOrDefault();
                    answer.Question = null;
                }
                templist.Add(new QuestionPageModel()
                {
                    ishot=i.ishot,
                    Id=i.Id,
                    state=i.state,
                    regdate=i.regdate,
                    regman=i.regman,
                    regmanid=i.regmanid,
                    title=i.title,
                    Type=i.Type,
                    Answer = answer,
                    content=i.content,
                    typeid=i.typeid
                });

            }
            templist = templist.OrderByDescending(o => o.regdate).ToList();
            model.list = templist;
            return Json(model, JsonRequestBehavior.AllowGet);
        }