Esempio n. 1
0
        public IList<string> AddEntry(FormEntry formEntryDto)
        {
            formEntryDto.EntryDate = DateTime.Now;
            formEntryDto.Ip = HttpContext.Current.Request.GetClientIpAddress();

            var form = _h5FormsContext.Forms.Single(f => f.Id == formEntryDto.FormId);
            var formDto = Mapper.Map<Entities.Form.Form, Form>(form);
            var result = default(IList<string>);

            formDto.SetValues(formEntryDto);

            #region Validation

            result = formDto.BasicValidation();

            if (result.Count > 0)
                return result;

            result = formDto.UniqueValidation(_h5FormsContext.IsUniqueEntry);

            if (result.Count > 0)
                return result;

            var formEntry = Mapper.Map<FormEntry, Entities.Form.FormEntry>(formEntryDto);

            #endregion

            _h5FormsContext.AddEntry(formEntry);

            return result;
        }
Esempio n. 2
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var form = controllerContext.HttpContext.Request.Form;

            var result = new FormEntry
            {
                ControlValues = new Dictionary<string, string>()
            };

            var aux = form.Get(FormSettings.FORM_ID_NAME);
            int formId;
            var validFormId = int.TryParse(aux, out formId);

            if (validFormId)
            {
                result.FormId = formId;

                foreach (var key in form.AllKeys.Where(k => k.StartsWith(FormSettings.COLUMN_PREFIX)))
                {
                    var values = form.GetValues(key).Select(v => v.Replace(FormSettings.SELECTED_VALUES_SEPARATOR.ToString(), string.Empty));
                    var value = string.Join(FormSettings.SELECTED_VALUES_SEPARATOR.ToString(), values) ;

                    result.ControlValues.Add(key, value);
                }
            }

            return result;
        }
Esempio n. 3
0
        public void SetValues(FormEntry formEntry)
        {
            foreach (var column in formEntry.ControlValues)
            {
                var controlId = int.Parse(column.Key.Replace(FormSettings.COLUMN_PREFIX,string.Empty));
                var control = Controls.Single(c => c.Id == controlId) as ValueControl;

                control.SetValue(column.Value);
            }
        }
        public ActionResult Test(FormEntry formEntry)
        {
            ModelState.Clear();

            var result = _formAdmin.AddEntry(formEntry);
            var form = _formAdmin.GetForm(formEntry.FormId);

            foreach (var message in result)
            {
                ModelState.AddModelError(string.Empty, message);
                form.SetValues(formEntry);
            }

            return View(form);
        }
        protected override void InitializeControls(GenericContainer container)
        {
            _currentSiteId = SystemManager.CurrentContext.CurrentSite.Id;
            _sfTrackingCookie = HttpContext.Current.Request.Cookies["sf-trckngckie"];

            switch (ExtendedFormType)
            {
                case "conditional":
                    _isConditionalForm = true;
                    break;
                case "progressive":
                    _isProgressiveForm = true;
                    break;
            }

            if (_isProgressiveForm)
            {
                _isProgressiveForm = true;
                _priorFormEntry = GetPriorFormEntry();
            }

            if (!this.IsLicensed)
            {
                this.ErrorsPanel.Visible = true;
                ControlCollection controls = this.ErrorsPanel.Controls;
                Label label = new Label()
                {
                    Text = Res.Get<FormsResources>().ModuleNotLicensed
                };

                controls.Add(label);
                return;
            }

            if (this.FormData != null)
            {
                bool flag = true;
                CultureInfo currentUICulture = CultureInfo.CurrentUICulture;

                if (this.CurrentLanguage != null)
                {
                    currentUICulture = new CultureInfo(this.CurrentLanguage);
                }

                if (!this.FormData.IsPublished(currentUICulture))
                {
                    flag = false;
                }

                if (flag)
                {
                    this.RenderFormFields();
                }
            }

            if (!this.formDescriptionFound && this.IsDesignMode())
            {
                this.ErrorsPanel.Visible = true;
                ControlCollection controlCollections = this.ErrorsPanel.Controls;
                Label label1 = new Label()
                {
                    Text = Res.Get<FormsResources>().TheSpecifiedFormNoLongerExists
                };

                controlCollections.Add(label1);
            }

            HttpContextBase currentHttpContext = SystemManager.CurrentHttpContext;

            if (currentHttpContext != null && this.formDescriptionFound)
            {
                if (!currentHttpContext.Items.Contains("PageFormControls"))
                {
                    currentHttpContext.Items["PageFormControls"] = string.Empty;
                }

                currentHttpContext.Items["PageFormControls"] = string.Format("{0}Id={1},ValidationGroup={2};", (string)currentHttpContext.Items["PageFormControls"], this.FormId, this.ValidationGroup);
            }
        }
        new private void SaveFormEntry(FormDescription description)
        {
            FormsManager manager = FormsManager.GetManager();
            FormEntry userHostAddress = null;

            if (_isProgressiveForm && _priorFormEntry == null)
            {
                FieldControl keyField = this.FieldControls.Where(fc => ((IFormFieldControl)fc).MetaField.FieldName == _progressiveKeyFieldName).FirstOrDefault() as FieldControl;

                if (keyField != null && !String.IsNullOrWhiteSpace((string)keyField.Value))
                {
                    _priorFormEntry = GetPriorFormEntryByKeyField((string)keyField.Value);
                }
            }

            if (_isProgressiveForm && _priorFormEntry != null)
            {
                string entryType = String.Format("{0}.{1}", manager.Provider.FormsNamespace, this.FormData.Name);

                userHostAddress = manager.GetFormEntry(entryType, _priorFormEntry.Id);
            }
            else
            {
                userHostAddress = manager.CreateFormEntry(string.Format("{0}.{1}", manager.Provider.FormsNamespace, description.Name));
            }
            
            foreach (IFormFieldControl formFieldControl in this.FieldControls)
            {
                FieldControl fieldControl = formFieldControl as FieldControl;
                object value = fieldControl.Value;

                if (fieldControl.GetType().Name == "FormFileUpload")
                {
                    typeof(FormsControl)
                        .GetMethod("SaveFiles", BindingFlags.Static | BindingFlags.NonPublic)
                        .Invoke(null, new object[] { value as UploadedFileCollection, manager, description, userHostAddress, formFieldControl.MetaField.FieldName });
                }
                else if (!(value is List<string>))
                {
                    userHostAddress.SetValue(formFieldControl.MetaField.FieldName, value);
                }
                else
                {
                    StringArrayConverter stringArrayConverter = new StringArrayConverter();
                    object obj = stringArrayConverter.ConvertTo((value as List<string>).ToArray(), typeof(string));

                    userHostAddress.SetValue(formFieldControl.MetaField.FieldName, obj);
                }
            }
            userHostAddress.IpAddress = this.Page.Request.UserHostAddress;
            userHostAddress.SubmittedOn = DateTime.UtcNow;

            Guid userId = ClaimsManager.GetCurrentUserId();

            userHostAddress.UserId = userId == Guid.Empty ? Guid.Parse(_sfTrackingCookie.Value) : userId;

            if (userHostAddress.UserId == userId)
            {
                userHostAddress.Owner = userId;
            }

            if (SystemManager.CurrentContext.AppSettings.Multilingual)
            {
                userHostAddress.Language = CultureInfo.CurrentUICulture.Name;
            }

            FormDescription formData = this.FormData;
            formData.FormEntriesSeed = formData.FormEntriesSeed + (long)1;
            userHostAddress.ReferralCode = this.FormData.FormEntriesSeed.ToString();

            manager.SaveChanges();
        }