示例#1
0
        private Email GetEmail(Web web, Domain domain, Page page, FormSettings formSettings, IList <FormElementFieldValue> fieldValues)
        {
            // Get to recipients
            IEnumerable <EmailAddress> toAddresses = GetEmailAddresses(new string[] { "\r\n", "\n" }, formSettings.RecipientEmail);
            IEnumerable <EmailAddress> configurationToAddresses = _emailConfigurationService.GetToEmailRecipients();

            if (configurationToAddresses != null)
            {
                toAddresses.Concat(configurationToAddresses);
            }

            // Get from (and reply to) email address
            string       host             = _webHelperService.GetHostFromUrl(domain.Url, true).ToLower();
            EmailAddress fromEmailAddress = new EmailAddress {
                Email = string.Format("donotreply@{0}", host), DisplayName = web.Name
            };

            // Return email to send
            return(new Email
            {
                BccAddresses = _emailConfigurationService.GetBccEmailRecipients(),
                Content = GetEmailContent(page, fieldValues),
                FromAddress = fromEmailAddress,
                ReplyToAddress = fromEmailAddress,
                ToAddresses = toAddresses,
            });
        }
示例#2
0
        private Form GetUserForm(string context)
        {
            // Get page and element identifiers
            string[] parts     = context.Split('|');
            long     pageId    = Convert.ToInt64(parts[1]);
            long     elementId = Convert.ToInt64(parts[2]);

            // Get form settings
            Guid elementTypeId = FormId;
            IAdvancedElementService elementService = (IAdvancedElementService)_elementFactory.GetElementService(elementTypeId);
            FormSettings            formSettings   = (FormSettings)elementService.New(_authenticationService.TenantId);

            formSettings.ElementId = elementId;
            elementService.Read(formSettings);

            // Construct form
            Form form = new Form
            {
                FieldSets   = new List <FormFieldSet>(),
                Id          = FormId.ToString(),
                Context     = context,
                SubmitLabel = formSettings.SubmitButtonLabel
            };

            // Populate fields from form settings
            foreach (FormElementField formElementField in formSettings.Fields)
            {
                FormFieldSet fieldSet = new FormFieldSet {
                    Fields = new Dictionary <string, IFormField>()
                };
                switch (formElementField.FieldType)
                {
                case FormElementFieldType.TextField:
                    fieldSet.Fields.Add("field", new TextField
                    {
                        Name                 = "field_" + formElementField.FormFieldId,
                        Label                = formElementField.Label,
                        Required             = formElementField.Required,
                        RequiredErrorMessage = string.Format(ElementResource.FormFieldRequiredMessage, formElementField.Label)
                    });
                    break;

                case FormElementFieldType.MultiLineTextField:
                    fieldSet.Fields.Add("field", new MultiLineTextField
                    {
                        Name                 = "field_" + formElementField.FormFieldId,
                        Label                = formElementField.Label,
                        Required             = formElementField.Required,
                        RequiredErrorMessage = string.Format(ElementResource.FormFieldRequiredMessage, formElementField.Label),
                        Rows                 = 5
                    });
                    break;
                }
                form.FieldSets.Add(fieldSet);
            }

            // Return form
            return(form);
        }
        private FormFieldCollection GetFormFieldCollection(FormSettings settings)
        {
            FormFieldCollection formFieldCollection = new FormFieldCollection();

            foreach (FormElementField field in settings.Fields)
            {
                formFieldCollection.Add(field);
            }
            return(formFieldCollection);
        }
示例#4
0
        /// <summary>
        /// Sends submitted form field values to recipient. TODO: Verify submitted form fields are as specified in form definition.
        /// </summary>
        /// <param name="tenantId">Website identifier.</param>
        /// <param name="pageId">The page containing the form that has been submitted.</param>
        /// <param name="elementId">Identifies element whose fields are being sent.</param>
        /// <param name="fieldValues">Field values to send.</param>
        /// <param name="unitOfWork">Unit of work.</param>
        public void Send(long tenantId, long pageId, long elementId, IList <FormElementFieldValue> fieldValues, IUnitOfWork unitOfWork = null)
        {
            // Get form settings
            FormSettings formSettings = (FormSettings)New(tenantId);

            formSettings.ElementId = elementId;
            Read(formSettings, unitOfWork);

            // Get page, web and domain settings
            Page   page   = _pageService.Read(tenantId, pageId, unitOfWork);
            Web    web    = _authenticationService.Web;
            Domain domain = _authenticationService.Domain;

            // Construct email
            Email email = GetEmail(web, domain, page, formSettings, fieldValues);

            // Send finished email
            _emailService.SendEmail(email);
        }
        public void Read(FormSettings settings, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                dbm.SetSQL(_sqlManager.GetSql("Sql.ReadForm.sql"));
                dbm.AddParameter("@TenantId", FieldType.BigInt, settings.TenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, settings.ElementId);
                dbm.ExecuteReader();
                dbm.Read();
                settings.RecipientEmail    = (string)dbm.DataReaderValue("RecipientEmail");
                settings.SubmitButtonLabel = (string)dbm.DataReaderValue("SubmitButtonLabel");
                settings.SubmittedMessage  = (string)dbm.DataReaderValue("SubmittedMessage");
                settings.Fields            = new List <FormElementField>();
                dbm.Read();
                while (dbm.Read())
                {
                    settings.Fields.Add(new FormElementField
                    {
                        TenantId    = (long)dbm.DataReaderValue("TenantId"),
                        ElementId   = (long)dbm.DataReaderValue("ElementId"),
                        FormFieldId = (long)dbm.DataReaderValue("FormFieldId"),
                        SortOrder   = (int)dbm.DataReaderValue("SortOrder"),
                        FieldType   = (FormElementFieldType)(int)dbm.DataReaderValue("FormFieldType"),
                        Label       = (string)dbm.DataReaderValue("Label"),
                        Required    = (bool)dbm.DataReaderValue("Required")
                    });
                }
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }
        public void Create(FormSettings settings, IUnitOfWork unitOfWork = null)
        {
            FormFieldCollection formFieldCollection = GetFormFieldCollection(settings);
            IUnitOfWork         localUnitOfWork     = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null;

            try
            {
                IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork ?? localUnitOfWork);
                dbm.SetSQL(_sqlManager.GetSql("Sql.CreateForm.sql"));
                dbm.AddParameter("@TenantId", FieldType.BigInt, settings.TenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, settings.ElementId);
                dbm.AddParameter("@RecipientEmail", FieldType.NVarChar, -1, settings.RecipientEmail);
                dbm.AddParameter("@SubmitButtonLabel", FieldType.NVarChar, 100, settings.SubmitButtonLabel);
                dbm.AddParameter("@SubmittedMessage", FieldType.NVarChar, -1, settings.SubmittedMessage);
                dbm.AddTypedParameter("@FormFields", FieldType.Structured, formFieldCollection.Count == 0 ? null : formFieldCollection, "element.FormFieldTableType");
                dbm.ExecuteNonQuery();
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Commit();
                }
            }
            catch
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw;
            }
            finally
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Dispose();
                }
            }
        }
示例#7
0
        private Form GetAdminForm(string context)
        {
            // Check permissions
            _authorizationService.AuthorizeUserForFunction(Functions.UpdatePageElements);

            // Get page and element identifiers
            string[] parts     = context.Split('|');
            long     pageId    = Convert.ToInt64(parts[1]);
            long     elementId = Convert.ToInt64(parts[2]);

            // Get current form settings
            IAdvancedElementService elementService = (IAdvancedElementService)_elementFactory.GetElementService(FormId);
            FormSettings            formSettings   = (FormSettings)elementService.New(_authenticationService.TenantId);

            formSettings.ElementId = elementId;
            elementService.Read(formSettings);

            // Construct main form
            Form form = new Form {
                Fields = new Dictionary <string, IFormField>(), Id = FormId.ToString(), Context = context, FieldSets = new List <FormFieldSet>()
            };

            form.Fields.Add("recipientEmail", new MultiLineTextField
            {
                Name                 = "recipientEmail",
                Label                = ElementResource.FormRecipientEmailLabel,
                Required             = true,
                RequiredErrorMessage = ElementResource.FormRecipientEmailRequiredMessage,
                Value                = formSettings.RecipientEmail,
                Rows                 = 4
            });
            form.Fields.Add("submitButtonLabel", new TextField
            {
                Name                  = "submitButtonLabel",
                Label                 = ElementResource.FormSubmitButtonLabelLabel,
                Required              = true,
                RequiredErrorMessage  = ElementResource.FormSubmitButtonLabelRequiredMessage,
                MaxLength             = FormLengths.SubmitButtonLabelMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.FormSubmitButtonLabelMaxLengthMessage, "submitButtonLabel", FormLengths.SubmitButtonLabelMaxLength),
                Value                 = formSettings.SubmitButtonLabel
            });
            form.Fields.Add("submittedMessage", new TextField
            {
                Name                 = "submittedMessage",
                Label                = ElementResource.FormSubmittedMessageLabel,
                Required             = true,
                RequiredErrorMessage = ElementResource.FormSubmittedMessageRequiredMessage,
                Value                = formSettings.SubmittedMessage
            });
            form.SubmitLabel = ElementResource.FormButtonLabel;

            // Add form fields
            foreach (FormElementField field in formSettings.Fields)
            {
                FormFieldSet fieldSet = new FormFieldSet {
                    Fields = new Dictionary <string, IFormField>()
                };
                fieldSet.Fields.Add("label", new TextField
                {
                    Name                 = string.Format("field_{0}_label", field.FormFieldId),
                    Label                = ElementResource.FormFieldLabelLabel,
                    Required             = true,
                    RequiredErrorMessage = ElementResource.FormFieldLabelRequiredMessage,
                    Value                = field.Label
                });
                fieldSet.Fields.Add("type", new SelectListField <string>
                {
                    Name  = string.Format("field_{0}_type", field.FormFieldId),
                    Label = ElementResource.FormFieldTypeLabel,
                    Value = field.FieldType.ToString(),
                    Items = new List <ListFieldItem <string> > {
                        new ListFieldItem <string> {
                            Name = ElementResource.FormFieldTypeTextLabel, Value = FormElementFieldType.TextField.ToString()
                        },
                        new ListFieldItem <string> {
                            Name = ElementResource.FormFieldTypeMultiLineLabel, Value = FormElementFieldType.MultiLineTextField.ToString()
                        },
                    }
                });
                fieldSet.Fields.Add("required", new BooleanField
                {
                    Name  = string.Format("field_{0}_required", field.FormFieldId),
                    Label = ElementResource.FormFieldRequiredLabel,
                    Value = field.Required
                });
                form.FieldSets.Add(fieldSet);
            }

            // Fields set containing default fields for a new form field
            form.NamedFieldSets = new Dictionary <string, FormFieldSet>();
            FormFieldSet namedFieldSet = new FormFieldSet {
                Fields = new Dictionary <string, IFormField>()
            };
            long formFieldId = 0;

            namedFieldSet.Fields.Add("label", new TextField
            {
                Name                 = string.Format("field_{0}_label", formFieldId),
                Label                = ElementResource.FormFieldLabelLabel,
                Required             = true,
                RequiredErrorMessage = ElementResource.FormFieldLabelRequiredMessage,
                Value                = ElementResource.FormFieldLabelDefaultValue
            });
            namedFieldSet.Fields.Add("type", new SelectListField <string>
            {
                Name  = string.Format("field_{0}_type", formFieldId),
                Label = ElementResource.FormFieldTypeLabel,
                Value = FormElementFieldType.TextField.ToString(),
                Items = new List <ListFieldItem <string> > {
                    new ListFieldItem <string> {
                        Name = ElementResource.FormFieldTypeTextLabel, Value = FormElementFieldType.TextField.ToString()
                    },
                    new ListFieldItem <string> {
                        Name = ElementResource.FormFieldTypeMultiLineLabel, Value = FormElementFieldType.MultiLineTextField.ToString()
                    },
                }
            });
            namedFieldSet.Fields.Add("required", new BooleanField
            {
                Name  = string.Format("field_{0}_required", formFieldId),
                Label = ElementResource.FormFieldRequiredLabel,
                Value = false
            });
            form.NamedFieldSets.Add("newField", namedFieldSet);

            // Return result
            return(form);
        }