Example #1
0
        public static string Format(this TemplateFieldValueViewModel value, bool stripHtml = false)
        {
            switch (value.FieldType)
            {
            case Constants.TemplateFieldType.BMI:
                BMIViewModel bmi;
                if (!string.IsNullOrEmpty(value.Value) && value.Value.Length > 0)
                {
                    bmi = value.Value.FromJson <BMIViewModel>();
                    return(bmi.Format());
                }
                return("--");

            case Constants.TemplateFieldType.BIRTHDAYPICKER:
                DateTime dateVal;
                if (!string.IsNullOrEmpty(value.Value) && DateTime.TryParse(value.Value, out dateVal))
                {
                    return(dateVal.ToString("dd MMM yyyy"));
                }
                return(value.Value.ToString("--"));

            case Constants.TemplateFieldType.ADDRESS:
                AddressViewModel address;
                if (!string.IsNullOrEmpty(value.Value) && value.Value.Length > 0)
                {
                    address = value.Value.FromJson <AddressViewModel>();
                    return(address.Format());
                }
                return("--");

            case Constants.TemplateFieldType.CHECKBOX:
                if (!string.IsNullOrEmpty(value.Value) && value.Value.Length > 0)
                {
                    if (!stripHtml)
                    {
                        var           values = value.Value.Split(Constants.Form_Option_Split);
                        StringBuilder sb     = new StringBuilder("<ul class=\"vertical-list selected-checkbox-list\"");
                        values.Each((val, index) =>
                        {
                            sb.AppendFormat("<li>{0}</li>", val);
                        });
                        return(sb.ToString());
                    }
                    else
                    {
                        return(value.Value);
                    }
                }
                return("");

            case Constants.TemplateFieldType.FILEPICKER:

                return("");
            }

            return(value.Value);
        }
Example #2
0
        public IEnumerable <TemplateFieldValueViewModel> GetTemplateFieldValuesByForm(TemplateViewModel model)
        {
            var fieldValues = GetTemplateFieldValuesByTemplate(model.TemplateID.Value);
            var values      = fieldValues
                              .Select((fv) =>
            {
                return(TemplateFieldValueViewModel.CreateFromObject(fv));
            })
                              .OrderBy(f => f.FieldOrder)
                              .ThenByDescending(f => f.DateAdded);

            return(values);
        }
Example #3
0
        public void FillIn_SuccessWithCheckbox()
        {
            FormViewModel formViewModel = new FormViewModel();

            formViewModel.Title = "Required Form Name";
            Template template = _formManager.CreateNewFormAndTemplate(formViewModel);

            Assert.IsNotNull(template);

            TemplateViewModel templateViewModel = _formManager.FindTemplateToEdit(template.TemplateID);

            FormCollection fieldCollection = new FormCollection();
            IDictionary <string, string> fields;

            CeateFieldForm(1, Constants.TemplateFieldType.CHECKBOX.ToString(), fieldCollection, out fields);
            fieldCollection.Add("Fields[" + 1 + "].Options", "Test1,1234|Test423|helloworld");

            _formManager.UpdateTemplate(templateViewModel, fieldCollection, fields);

            templateViewModel = _formManager.FindTemplateToEdit(template.TemplateID);
            Assert.IsNotNull(templateViewModel.Fields);
            Assert.AreEqual(1, templateViewModel.Fields.Count);

            templateViewModel.Entries = _formManager.HasSubmissions(templateViewModel).ToList();
            Assert.AreEqual(0, templateViewModel.Entries.Count);

            FormCollection submissionCollection = new FormCollection();

            submissionCollection.Add("SubmitFields[1].CheckBox", "Test1,1234,helloworld");

            IDictionary <string, string> submissionFields = new System.Collections.Generic.Dictionary <string, string>();

            submissionFields.Add("1", "1");

            string result = _target.FillIn(submissionFields, templateViewModel, submissionCollection);

            Assert.AreEqual(result, "success");

            templateViewModel.Entries = _formManager.HasSubmissions(templateViewModel).ToList();

            Assert.AreEqual(0, _unitOfWork.PreRegistrations.GetAll().Count());

            Assert.AreEqual(1, templateViewModel.Entries.Count);

            TemplateFieldValueViewModel templateFieldValue = templateViewModel.Entries.FirstOrDefault();

            Assert.AreEqual("Test1,1234|helloworld", templateFieldValue.Value);
        }
Example #4
0
        public IEnumerable <TemplateFieldValueViewModel> HasSubmissions(TemplateViewModel model)
        {
            using (var unitOfWork = CreateUnitOfWork())
            {
                var fieldValues = unitOfWork.FormRepository.GetTemplateFieldValuesByTemplate(model.TemplateID.Value);
                var values      = fieldValues
                                  .Select((fv) =>
                {
                    return(TemplateFieldValueViewModel.CreateFromObject(fv));
                })
                                  .OrderBy(f => f.FieldOrder)
                                  .ThenByDescending(f => f.DateAdded);

                return(values);
            }
        }
Example #5
0
        public void FillIn_SuccessWithBirthdayPickerDoubleDigitMonth()
        {
            Template          template;
            TemplateViewModel templateViewModel;
            FormViewModel     formViewModel = new FormViewModel();

            formViewModel.Title = "Required Form Name";
            CreateTemplateAndField(formViewModel, Constants.TemplateFieldType.BIRTHDAYPICKER, out template, out templateViewModel);

            templateViewModel = _formManager.FindTemplateToEdit(template.TemplateID);
            Assert.IsNotNull(templateViewModel.Fields);
            Assert.AreEqual(1, templateViewModel.Fields.Count);

            templateViewModel.Entries = _formManager.HasSubmissions(templateViewModel).ToList();
            Assert.AreEqual(0, templateViewModel.Entries.Count);

            FormCollection submissionCollection = new FormCollection();

            submissionCollection.Add("SubmitFields[1].Day", "09");
            submissionCollection.Add("SubmitFields[1].Month", "11");
            submissionCollection.Add("SubmitFields[1].Year", "2017");

            IDictionary <string, string> submissionFields = new System.Collections.Generic.Dictionary <string, string>();

            submissionFields.Add("1", "1");

            string result = _target.FillIn(submissionFields, templateViewModel, submissionCollection);

            Assert.AreEqual(result, "success");

            templateViewModel.Entries = _formManager.HasSubmissions(templateViewModel).ToList();

            Assert.AreEqual(0, _unitOfWork.PreRegistrations.GetAll().Count());

            Assert.AreEqual(1, templateViewModel.Entries.Count);

            TemplateFieldValueViewModel templateFieldValue = templateViewModel.Entries.FirstOrDefault();

            Assert.AreEqual("09/11/2017 12:00:00 AM", templateFieldValue.Value);
        }