Esempio n. 1
0
        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;
        }
Esempio n. 2
0
        public ActionResult Parse(string mandrill_events)
        {
            //Get the email message from the mandrill
            var    events  = JsonConvert.DeserializeObject <IEnumerable <Mandrill.MailEvent> >(mandrill_events);
            string message = events.FirstOrDefault().Msg.Html;
            string email   = events.FirstOrDefault().Msg.FromEmail;

            //Store the answer which will in the site
            string answerContent;


            if (message == null || message.Length == 0)
            {
                //Yahoo emails process
                message = events.FirstOrDefault().Msg.Text;
                if (message == null || message.Length == 0)
                {
                    UserMailer.FailedEmailAnswer(email);
                    return(new HttpStatusCodeResult(HttpStatusCode.OK));
                }
                answerContent = Regex.Split(message, "-------------------------------------------").FirstOrDefault();
            }
            else
            {
                //Gmail and hotmail process
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(message);
                var firstdiv = doc.DocumentNode.SelectSingleNode("//div");
                if (firstdiv == null)
                {
                    UserMailer.FailedEmailAnswer(email);
                    return(new HttpStatusCodeResult(HttpStatusCode.OK));
                }
                answerContent = firstdiv.InnerHtml;

                //Hotmail
                answerContent = Regex.Split(answerContent, "<hr id=\"stopSpelling\">").FirstOrDefault();
            }


            if (answerContent == null || answerContent.Length == 0)
            {
                UserMailer.FailedEmailAnswer(email);
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            //Get the question and user id
            var    subject = events.FirstOrDefault().Msg.Subject;
            string hash    = Regex.Split(subject, "Id:").LastOrDefault();

            if (hash == null || hash.Length == 0)
            {
                UserMailer.FailedEmailAnswer(email);
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }
            EmailIdentifier ei = UserManager.GetEmailDatasByHash(hash);

            if (ei == null)
            {
                UserMailer.FailedEmailAnswer(email);
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            //Check answer length
            if (answerContent.Length > 25000 || answerContent.Length < 25)
            {
                UserMailer.FailedEmailAnswer(email);
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            //Create the answer
            var ans = new Answer();

            ans.Content = answerContent;
            AnswerManager.AddAnswer(ans, ei.QuestionId, ei.UserId);
            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
Esempio n. 3
0
        protected void submit_Click(object sender, EventArgs e)
        {
            string[] content = Request.Form.GetValues("TA");
            for (int i = 0; i < ProblemList.Count; i++)
            {
                Answer answer = new Answer();
                answer.content = content[i];
                answer.student = stu.username;
                answer.problem = ProblemList[i].id;
                answer.score   = (float)0.0;
                answer.comment = "no comment";
                answer.major   = stu.major;
                answer.state   = "2";
                if (AnswerList == null)
                {
                    AnswerList = new List <Answer>();
                }
                AnswerList.Add(answer);
            }

            if (submitFlag)
            {
                AnswerMan.AddAnswer(AnswerList);

                if (accessory == null)
                {
                    accessory = new Accessory();
                }

                try
                {
                    //获取上传文件的路径
                    string filepath = FileUpload2.PostedFile.FileName;
                    //获取后缀名
                    int filepos = filepath.LastIndexOf(".");
                    //截取后缀名
                    String strfilename = filepath.Substring(filepos);
                    //获取时间
                    string time1 = System.DateTime.Now.ToString("yyyyMMddHHmmssffff");
                    //保存到服务器的路径,这是我们网站固定网址
                    string serverpath = Server.MapPath("Accessory") + "\\" + stu.username + "_" + id + "_" + time1 + strfilename;
                    //确定上传文件
                    FileUpload2.PostedFile.SaveAs(serverpath);

                    string DBFilePath = "http://tasksystem.apphb.com/Accessory/" + stu.username + "_" + id + "_" + time1 + strfilename;
                    accessory.adress     = DBFilePath;
                    accessory.assignment = System.Int32.Parse(id);
                    accessory.student    = stu.username;
                    AccessoryMan.Create(accessory);
                }
                catch (System.Exception error)
                {
                    Response.Write(error.Message.ToString());
                }
            }
            else
            {
                AnswerMan.UpdateAnswer(AnswerList);
                //accessory = AccessoryMan.GetAccessory(stu.username, System.Int32.Parse(id));
            }

            //Response.Redirect("StudentMainForm.aspx");
            Response.Write("<script language=javascript>alert('提交成功!');location='StudentMainForm.aspx'</script>");
        }