Example #1
0
        public string CreateQuestion()
        {
            if (!string.IsNullOrEmpty(Request["UserName"]) && !string.IsNullOrEmpty(Request["questionBody"]))
            {
                QandAContext qc = new QandAContext();

                string userName = Request["UserName"];
                string userContact = Request["UserContact"];
                string questionClass = Request["QuestionClass"];
                string questionSubject = Request["questionSubject"];
                string questionBody = Request["questionBody"];

                User u;
                int uCount = qc.Users.Where(us => us.Name == userName).Count();
                if (uCount == 0)
                {
                    u = new User();
                    u.Name = userName;
                    u.Contact = userContact;
                    qc.Users.Add(u);
                    qc.SaveChanges();
                }
                else
                {
                    u = qc.Users.Where(us => us.Name == userName).First();
                    u.Contact = userContact;
                }

                Qusetion qu = new Qusetion();
                qu.QuestionClass = qc.QuestionClasss.Find(Guid.Parse(questionClass));
                qu.Subject = questionSubject;
                qu.Body = questionBody;
                qu.SubmitUser = u;
                qu.SubmitTime = DateTime.Now;
                qu.State = qc.States.Where(s => s.Name == "待解决").First();

                qc.Qusetions.Add(qu);
                qc.SaveChanges();

                return "QuestionOK";
            }

            return "False";
        }
Example #2
0
        public string AnswerQuestion()
        {
            if (!string.IsNullOrEmpty(Request["UserName"]) && !string.IsNullOrEmpty(Request["AnswerBody"]))
            {
                QandAContext qc = new QandAContext();

                string userName = Request["UserName"];
                string userContact = Request["UserContact"];
                string questionID = Request["QuestionID"];
                string answerBody = Request["AnswerBody"];

                User u;
                int uCount = qc.Users.Where(us => us.Name == userName).Count();
                if (uCount == 0)
                {
                    u = new User();
                    u.Name = userName;
                    u.Contact = userContact;
                    qc.Users.Add(u);
                    qc.SaveChanges();
                }
                else
                {
                    u = qc.Users.Where(us => us.Name == userName).First();
                    u.Contact = userContact;
                }

                Qusetion qu = qc.Qusetions.Find(Guid.Parse(questionID));

                Answer an = new Answer();
                an.Body = answerBody;
                an.SubmitUser = u;
                an.SubmitTime = DateTime.Now;
                an.Qusetion = qu;

                qc.Answers.Add(an);

                qc.SaveChanges();

                return "AnswerOK";
            }

            return "False";
        }