protected void DataBind(int surveyId)
        {
            SurveyInfo surveyById = SurveyManager.GetSurveyById(surveyId);

            this.ViewState["surveyInfo"] = surveyById;
            this.SurveyContent.Value     = SurveyCreate.GetSurveyTemplate(surveyById);
            string fileName = surveyById.FileName;

            if (string.IsNullOrEmpty(fileName))
            {
                fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";
            }
            string[] strArray = fileName.Split(new char[] { '.' });
            string   str2     = strArray[1];

            this.HdnShortFileName.Value = strArray[0];
            this.HdnFileName.Value      = fileName;
            if (str2 == "html")
            {
                this.RadlPageType.SelectedValue = "0";
            }
            else
            {
                this.RadlPageType.SelectedValue = "1";
            }
            this.TxtFileName.Text  = fileName;
            this.HdnSurveyId.Value = surveyId.ToString();
        }
        public ActionResult Create(SurveyCreate survey)
        {
            QuestionService _questionService = new QuestionService();
            bool            surveySaved      = false;

            Survey newSurvey = new Survey()
            {
                SurveyTitle       = survey.SurveyTitle,
                SurveyDescription = survey.SurveyDescription,
                StartDate         = survey.StartDate,
                EndDate           = survey.EndDate
            };

            if (ModelState.IsValid)
            {
                db.Surveys.Add(newSurvey);
                db.SaveChanges();
                surveySaved = true;
            }

            List <SurveyQuestion> surveyQuestions = new List <SurveyQuestion>();
            int i = 0;

            foreach (int questionId in survey.SelectedSurveyQuestions)
            {
                Question currQuestion = _questionService.GetQuestionById(questionId);
                surveyQuestions.Add(new SurveyQuestion()
                {
                    QuestionId = questionId,
                    SurveyId   = newSurvey.SurveyId,
                    Order      = i
                });

                i++;
            }

            if (surveyQuestions.Count > 0)
            {
                db.SurveyQuestions.AddRange(surveyQuestions);
                db.SaveChanges();
            }

            if (surveySaved)
            {
                return(RedirectToAction("Index"));
            }

            return(View(survey));
        }
Esempio n. 3
0
        public bool CreateSurvey(SurveyCreate model)
        {
            var entity =
                new Survey()
            {
                SurveyTitle       = model.SurveyTitle,
                SurveyDescription = model.SurveyDescription,
                StartDate         = model.StartDate,
                EndDate           = model.EndDate
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Surveys.Add(entity);
                ctx.SaveChanges();
            }
            return(true);
        }
 protected void BtnCreate_Click(object sender, EventArgs e)
 {
     if (this.Page.IsValid)
     {
         int surveyId = DataConverter.CLng(this.HdnSurveyId.Value);
         if (surveyId == 0)
         {
             AdminPage.WriteErrMsg("<li>请指定问卷ID!</li>");
         }
         else
         {
             bool flag = false;
             if ((this.TxtFileName.Text != this.HdnFileName.Value) && SurveyCreate.FileNameExists(this.TxtFileName.Text))
             {
                 flag = true;
             }
             if (!flag)
             {
                 string file          = HttpContext.Current.Server.MapPath(@"~\Survey\") + DataSecurity.FilterBadChar(this.TxtFileName.Text);
                 string createContent = this.SurveyContent.Value;
                 if (this.RadlPageType.SelectedValue == "1")
                 {
                     createContent = SurveyCreate.GetDynamicContent(createContent, surveyId);
                 }
                 FileSystemObject.WriteFile(file, createContent);
                 SurveyInfo surveyInfo = this.ViewState["surveyInfo"] as SurveyInfo;
                 surveyInfo.FileName = this.TxtFileName.Text;
                 SurveyManager.Update(surveyInfo);
                 AdminPage.WriteSuccessMsg("创建页面成功!保存在../Survey/" + this.TxtFileName.Text, "SurveyManage.aspx");
             }
             else
             {
                 AdminPage.WriteErrMsg("<li>已存在相同的问卷名,请指定另外的文件名!</li>");
             }
         }
     }
 }
Esempio n. 5
0
        public ActionResult Create(FormCollection values)
        {
            var survey = new SurveyCreate();

            TryUpdateModel(survey);

            try
            {
                Question newQuestion = new Question();
                newQuestion.Text = survey.QuestionText;

                db.Questions.Add(newQuestion);
                db.SaveChanges();


                //костыли
                int newQestId = db.Questions.Single(q => q.Text == survey.QuestionText).QuestionId;

                AnswerVariant newAW = new AnswerVariant {
                    QuestionId = newQestId, Text = survey.AnsverVariant1
                };
                db.AnswerVariants.Add(newAW); db.SaveChanges();
                newAW.Text = survey.AnsverVariant2;
                db.AnswerVariants.Add(newAW); db.SaveChanges();


                if (!String.IsNullOrEmpty(survey.AnsverVariant3) &&
                    !String.IsNullOrWhiteSpace(survey.AnsverVariant3))
                {
                    newAW.Text = survey.AnsverVariant3;
                    db.AnswerVariants.Add(newAW); db.SaveChanges();
                }

                if (!String.IsNullOrEmpty(survey.AnsverVariant4) &&
                    !String.IsNullOrWhiteSpace(survey.AnsverVariant4))
                {
                    newAW.Text = survey.AnsverVariant4;
                    db.AnswerVariants.Add(newAW); db.SaveChanges();
                }

                if (!String.IsNullOrEmpty(survey.AnsverVariant5) &&
                    !String.IsNullOrWhiteSpace(survey.AnsverVariant5))
                {
                    newAW.Text = survey.AnsverVariant5;
                    db.AnswerVariants.Add(newAW); db.SaveChanges();
                }

                if (!String.IsNullOrEmpty(survey.AnsverVariant6) &&
                    !String.IsNullOrWhiteSpace(survey.AnsverVariant6))
                {
                    newAW.Text = survey.AnsverVariant6;
                    db.AnswerVariants.Add(newAW); db.SaveChanges();
                }

                if (!String.IsNullOrEmpty(survey.AnsverVariant7) &&
                    !String.IsNullOrWhiteSpace(survey.AnsverVariant7))
                {
                    newAW.Text = survey.AnsverVariant7;
                    db.AnswerVariants.Add(newAW); db.SaveChanges();
                }

                if (!String.IsNullOrEmpty(survey.AnsverVariant8) &&
                    !String.IsNullOrWhiteSpace(survey.AnsverVariant8))
                {
                    newAW.Text = survey.AnsverVariant8;
                    db.AnswerVariants.Add(newAW); db.SaveChanges();
                }

                if (!String.IsNullOrEmpty(survey.AnsverVariant9) &&
                    !String.IsNullOrWhiteSpace(survey.AnsverVariant9))
                {
                    newAW.Text = survey.AnsverVariant9;
                    db.AnswerVariants.Add(newAW); db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(survey));
            }
        }