Exemplo n.º 1
0
        public override object GetContent(object model)
        {
            securityService.CreateAccessContext();

            if (FormId > 0)
            {
                SubmissionService subSrv = new SubmissionService(new CatfishDbContext());

                Form form = subSrv.CreateSubmissionForm(
                    FormId,
                    EnforceLists,
                    ShuffleBlocks,
                    ShuffleQuestions,
                    QuestionStepOption,
                    QuestionPartsStepOption);

                if (EnableReferenceCodes)
                {
                    Random rand = new Random();
                    form.ReferenceCode = DateTime.Now.ToString("yyMMdd-HHmmss-") + rand.Next(1000, 10000);
                }

                FormViewModel = new FormViewModel()
                {
                    Form         = form,
                    ItemId       = 0,
                    MaxImageSize = MaxPixelLength
                };
            }

            return(base.GetContent(model));
        }
Exemplo n.º 2
0
        public override object GetContent(object model)
        {
            if (FormId > 0)
            {
                SubmissionService subSrv = new SubmissionService(new CatfishDbContext());

                Form form = subSrv.CreateSubmissionForm(FormId);

                FormViewModel = new FormViewModel()
                {
                    Form   = form,
                    ItemId = 0
                };
            }

            return(base.GetContent(model));
        }
Exemplo n.º 3
0
        // GET: Forms
        public ActionResult Index()
        {
            var model = GetModel();

            ViewBag.PageModel = model;

            FormContainer formContainer = model.Region <FormContainer>("FormContainer");

            Form form = SubmissionService.CreateSubmissionForm(formContainer.FormId);

            FormViewModel vm = new FormViewModel()
            {
                Form   = form,
                ItemId = 0
            };

            return(View(model.GetView(), vm));
        }
        // GET: Forms
        public ActionResult Index()
        {
            var model = GetModel();

            ViewBag.PageModel = model;

            FormContainer formContainer = model.Region <FormContainer>("FormContainer");

            Form form = SubmissionService.CreateSubmissionForm(
                formContainer.FormId,
                formContainer.EnforceLists,
                formContainer.ShuffleBlocks,
                formContainer.ShuffleQuestions,
                formContainer.QuestionStepOption,
                formContainer.QuestionPartsStepOption);

            FormViewModel vm = new FormViewModel()
            {
                Form   = form,
                ItemId = 0
            };

            return(View(model.GetView(), vm));
        }
Exemplo n.º 5
0
        public void SaveSubmissionTest()
        {
            DatabaseHelper    Dh      = new DatabaseHelper(true);
            SubmissionService SubSrv  = new SubmissionService(Dh.Db);
            ItemService       ItemSrv = new ItemService(Dh.Db);

            string testName        = "Test 2";
            string testDescription = "This is a form for the second test.";
            string testPrefix      = "Test 2 ";
            Form   form1           = CreateFormTemplate(SubSrv, testName, testDescription, testPrefix);

            Dh.Db.SaveChanges();

            Form submission = SubSrv.CreateSubmissionForm(form1.Id);

            Assert.AreEqual(submission.Name, testName);
            Assert.AreEqual(submission.Description, testDescription);
            Assert.AreNotEqual(0, submission.Fields.Count);

            foreach (FormField field in submission.Fields)
            {
                Assert.IsTrue(field.Name.StartsWith(testPrefix));
                Type fieldType = field.GetType();

                if (typeof(RadioButtonSet).IsAssignableFrom(fieldType))
                {
                    var options = ((RadioButtonSet)field).Options;
                    options[0].Selected = true;
                    field.SetValues(new string[] { options[0].Value[0].Value });
                }
                else
                {
                    field.SetValues(new string[] { "TESTING RESULT" });
                }
            }

            submission.Serialize();
            CFItem itemCreated = SubSrv.SaveSubmission(submission, null, 0, Dh.Db.EntityTypes.FirstOrDefault().Id, form1.Id, Dh.Db.Collections.FirstOrDefault().Id);

            Dh.Db.SaveChanges();

            CFItem item = ItemSrv.GetItem(itemCreated.Id);

            Assert.IsTrue(item.Id > 0);
            Assert.AreNotEqual(0, item.FormSubmissions.FirstOrDefault().FormData.Fields.Count);

            foreach (FormField field in item.FormSubmissions.FirstOrDefault().FormData.Fields)
            {
                Assert.IsTrue(field.Name.StartsWith(testPrefix));
                Type fieldType = field.GetType();

                if (typeof(RadioButtonSet).IsAssignableFrom(fieldType))
                {
                    Assert.IsTrue(((RadioButtonSet)field).Options[0].Selected);
                }
                else
                {
                    Assert.AreEqual("TESTING RESULT", field.GetValues().FirstOrDefault().Value);
                }
            }
        }