Exemple #1
0
        public virtual ActionResult AlreadySubmitted()
        {
            // Mode for having already submitted the form - data is loaded but locked, and we display a "thank you" message at the top.
            ViewBag.curPage = "Home";
            var db = Current.DB;

            var responses = db.Responses.Where(r => r.UserId == Current.UserID.Value);
            if (!responses.Any()) // no responses exist for this user, i.e. they haven't submitted the form yet, so we're in the wrong place
            {
                return RedirectToAction("Index");
            }

            if (System.Configuration.ConfigurationManager.AppSettings["ResultsOpen"] == "true")
            {
                return RedirectToAction("Results"); // show results page
            }

            var model = new SubmitViewModel();
            foreach (var q in db.Questions)
            {
                model.Questions.Add(new QuestionDisplay() { qID = q.Id, Text = q.Text, Answers = q.Answers.ToList(), SelectedAnswer = db.Responses.Single(r=>r.UserId == Current.UserID.Value && r.QuestionId==q.Id).AnswerId });
            }
            model.AlreadySubmitted = true;
            model.FormCloses = DateTime.Parse(System.Configuration.ConfigurationManager.AppSettings["FormDeadline"]);
            return View("Index", model);
        }
Exemple #2
0
        public virtual ActionResult Index()
        {
            ViewBag.curPage = "Home";
            var db = Current.DB;

            var responses = db.Responses.Where(r => r.UserId == Current.UserID.Value);
            if (responses.Any()) // responses already exist for this user
            {
                if (System.Configuration.ConfigurationManager.AppSettings["ResultsOpen"] == "true")
                {
                    return RedirectToAction("Results"); // show results page
                }
                return RedirectToAction("AlreadySubmitted"); // show thank you screen
            }

            var deadline = DateTime.Parse(System.Configuration.ConfigurationManager.AppSettings["FormDeadline"]);
            if (DateTime.Now > deadline)
            {
                // The form deadline has passed and they have not submitted anything :(
                return View("MissedTheDeadline");
            }

            var model = new SubmitViewModel();
            model.FormCloses = deadline;
            foreach (var q in db.Questions.OrderBy(q=>q.Id))
            {
                model.Questions.Add(new QuestionDisplay() { qID = q.Id, Text = q.Text, Answers = q.Answers.OrderBy(a=>a.AnswerOrder).ToList()});
            }
            model.AlreadySubmitted = false;
            return View(model);
        }
Exemple #3
0
        public virtual ActionResult Index(SubmitViewModel model)
        {
            ViewBag.curPage = "Home";
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var db = Current.DB;

            // Just in case, start with blank slate
            db.Responses.DeleteAllOnSubmit(db.Responses.Where(r => r.UserId == Current.UserID));
            db.SubmitChanges();

            // Insert responses
            foreach (var q in model.Questions)
            {
                var r = new Response();
                r.UserId = Current.UserID.Value;
                r.QuestionId = q.qID;
                r.AnswerId = q.SelectedAnswer;
                r.Date = DateTime.UtcNow;
                db.Responses.InsertOnSubmit(r);
            }
            db.SubmitChanges();

            return RedirectToAction("AlreadySubmitted");
        }