예제 #1
0
        // GET: Surveys/Create
        public ActionResult Create(string error)
        {
            if (AccountController.CheckPermission("Survey-Create"))
            {
                if (error != null)
                {
                    ModelState.AddModelError("Questions", error);
                }
                UpdateList();
                System.Web.HttpContext.Current.Session["action"] = "Survey-Create";
                if (AccountController.CheckSession("Edit"))
                {
                    ViewBag.edit = true;
                    AccountController.ClearSession("Edit");
                }
                else
                {
                    ViewBag.edit = false;
                }
                ViewBag.SurveyTypeId = new SelectList(listSurveyType, "Id", "Type");
                ViewBag.UserId       = new SelectList(listUser, "Id", "Username");

                QuestionsController q = new QuestionsController();
                ViewBag.QuestionTypeId = new SelectList(q.GetQuestionType(), "Id", "Type");


                if (AccountController.CheckSurveyId())
                {
                    return(View(AccountController.GetSurvey()));
                }

                return(View());
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "Id,SurveyTypeId,Title,UserId,UserName,Description,SurveyType,IsBlock,IsDeleted,ModifiedDate,ModifiedUserId,DeletionDate,DeletionUserId,CreatedDate,CreatedUserId")] SurveyViewModel surveyViewModel, string CreateSurvey)
        {
            QuestionsController q = new QuestionsController();

            if (ModelState.IsValid)
            {
                if (CreateSurvey == "Create Survey")
                {
                    surveyViewModel.Id     = Guid.NewGuid();
                    surveyViewModel.UserId = AccountController.GetUser().Id;
                    surveyViewModel.AddSurvey(surveyViewModel);
                    AccountController.RememberSurveyId(surveyViewModel.Id);
                    UpdateList();
                    AccountController.RememberSurvey(listSurvey.Find(x => x.Id == surveyViewModel.Id));
                    AccountController.ClearCount();

                    ViewBag.SurveyTypeId = new SelectList(listSurveyType, "Id", "Type");
                    ViewBag.UserId       = new SelectList(listUser, "Id", "Username");

                    ViewBag.QuestionTypeId = new SelectList(q.GetQuestionType(), "Id", "Type");
                    return(View(surveyViewModel));
                }
                else if (CreateSurvey == "Edit Survey")
                {
                    SurveyViewModel s = AccountController.GetSurvey();
                    s.Title          = surveyViewModel.Title;
                    s.Description    = surveyViewModel.Description;
                    s.SurveyTypeId   = surveyViewModel.SurveyTypeId;
                    s.ModifiedUserId = AccountController.GetUser().Id;
                    TemporaryEdit(s);
                }
            }
            UpdateList();
            ViewBag.QuestionTypeId = new SelectList(q.GetQuestionType(), "Id", "Type");
            ViewBag.SurveyTypeId   = new SelectList(listSurveyType, "Id", "Type");
            ViewBag.UserId         = new SelectList(listUser, "Id", "Username");
            return(View(surveyViewModel));
        }
예제 #3
0
        // GET: Questions/Create
        //public ActionResult CreateQuestion()
        //{
        //    UpdateList();
        //    ViewBag.QuestionTypeId = new SelectList(listQuestionType, "Id", "Type");
        //    ViewBag.SurveyId = new SelectList(listSurvey, "Id", "Title");
        //    return View();
        //}

        public ActionResult CreateQuestion(Guid QuestionTypeId, string Content, int?Count, string[] dynamicField)
        {
            QuestionViewModel questionViewModel = new QuestionViewModel();

            if (QuestionTypeId != null && Content != null && Content != "")
            {
                questionViewModel.Id             = Guid.NewGuid();
                questionViewModel.QuestionTypeId = QuestionTypeId;
                questionViewModel.Content        = Content;
                questionViewModel.Number         = AccountController.Count();
                questionViewModel.SurveyId       = AccountController.GetSurveyId();
                questionViewModel.Survey         = AccountController.GetSurvey();
                questionViewModel.TimeLength     = TimeSpan.FromSeconds(3);

                if (Count != null)
                {
                    if (Count < 2)
                    {
                        return(RedirectToAction("Create", "Surveys", new { error = "Scale should more than two" }));
                    }
                    questionViewModel.IsScale = true;
                    questionViewModel.Count   = (int)Count;
                    questionViewModel.AddQuestion(questionViewModel);
                }
                else if (dynamicField.Count() > 0 && dynamicField[0] != "")
                {
                    questionViewModel.AddQuestion(questionViewModel);

                    List <QuestionAnswerViewModel> answer = new List <QuestionAnswerViewModel>();
                    QuestionAnswerViewModel        q      = new QuestionAnswerViewModel();
                    int i = 1;
                    foreach (var item in dynamicField)
                    {
                        if (item != "" && item != null)
                        {
                            q             = new QuestionAnswerViewModel();
                            q.Id          = Guid.NewGuid();
                            q.QuestionId  = questionViewModel.Id;
                            q.Answer      = item;
                            q.OrderNumber = i;
                            answer.Add(q);
                            i++;
                        }
                        else
                        {
                            return(RedirectToAction("Create", "Surveys", new { error = "Answer can't be empty" }));
                        }
                    }
                    foreach (var item in answer)
                    {
                        item.AddQuestionAnswer(item);
                    }
                }
                else
                {
                    questionViewModel.IsFreeText = true;
                    questionViewModel.AddQuestion(questionViewModel);
                }
                TemporaryQuestion();
                UpdateList();
                ViewBag.QuestionTypeId = new SelectList(listQuestionType, "Id", "Type", questionViewModel.QuestionTypeId);
                ViewBag.SurveyId       = new SelectList(listSurvey, "Id", "Title", questionViewModel.SurveyId);
                return(RedirectToAction("Create", "Surveys"));
            }
            UpdateList();
            ViewBag.QuestionTypeId = new SelectList(listQuestionType, "Id", "Type", questionViewModel.QuestionTypeId);
            ViewBag.SurveyId       = new SelectList(listSurvey, "Id", "Title", questionViewModel.SurveyId);
            return(RedirectToAction("Create", "Surveys", new { error = "Question can't be empty" }));
        }