Example #1
0
        public IElementContent GetContent(IElementSettings settings, IPageContext pageContext, IUnitOfWork unitOfWork = null)
        {
            ContactContent content = new ContactContent {
                PartialViewName = "Contact"
            };
            ContactSettings contactSettings = (ContactSettings)settings;

            if (contactSettings.FacebookUsername != null)
            {
                content.FacebookUrl = string.Format("https://www.facebook.com/{0}", contactSettings.FacebookUsername);
            }
            if (contactSettings.InstagramUsername != null)
            {
                content.InstagramUrl = string.Format("https://www.instagram.com/{0}", contactSettings.InstagramUsername);
            }
            if (contactSettings.LinkedInCompanyUsername != null)
            {
                content.LinkedInCompanyUrl = string.Format("https://www.linkedin.com/company/{0}", contactSettings.LinkedInCompanyUsername);
            }
            if (contactSettings.LinkedInPersonalUsername != null)
            {
                content.LinkedInPersonalUrl = string.Format("https://www.linkedin.com/in/{0}", contactSettings.LinkedInPersonalUsername);
            }
            if (contactSettings.TwitterUsername != null)
            {
                content.TwitterUrl = string.Format("https://twitter.com/{0}", contactSettings.TwitterUsername);
            }
            if (contactSettings.YouTubeChannelId != null)
            {
                content.YouTubeChannelUrl = string.Format("https://www.youtube.com/channel/{0}", contactSettings.YouTubeChannelId);
            }
            return(content);
        }
Example #2
0
        public void Read(ContactSettings settings, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                dbm.SetSQL(_sqlManager.GetSql("Sql.ReadContact.sql"));
                dbm.AddParameter("@TenantId", FieldType.BigInt, settings.TenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, settings.ElementId);
                dbm.ExecuteReader();
                dbm.Read();
                settings.DisplayName              = dbm.DataReaderValue("DisplayName") == DBNull.Value ? null : (string)dbm.DataReaderValue("DisplayName");
                settings.Preamble                 = dbm.DataReaderValue("Preamble") == DBNull.Value ? null : (string)dbm.DataReaderValue("Preamble");
                settings.Address                  = dbm.DataReaderValue("Address") == DBNull.Value ? null : (string)dbm.DataReaderValue("Address");
                settings.Email                    = dbm.DataReaderValue("Email") == DBNull.Value ? null : (string)dbm.DataReaderValue("Email");
                settings.FacebookUsername         = dbm.DataReaderValue("FacebookUsername") == DBNull.Value ? null : (string)dbm.DataReaderValue("FacebookUsername");
                settings.InstagramUsername        = dbm.DataReaderValue("InstagramUsername") == DBNull.Value ? null : (string)dbm.DataReaderValue("InstagramUsername");
                settings.LinkedInCompanyUsername  = dbm.DataReaderValue("LinkedInCompanyUsername") == DBNull.Value ? null : (string)dbm.DataReaderValue("LinkedInCompanyUsername");
                settings.LinkedInPersonalUsername = dbm.DataReaderValue("LinkedInPersonalUsername") == DBNull.Value ? null : (string)dbm.DataReaderValue("LinkedInPersonalUsername");
                settings.TelephoneNumber1         = dbm.DataReaderValue("TelephoneNumber1") == DBNull.Value ? null : (string)dbm.DataReaderValue("TelephoneNumber1");
                settings.TelephoneNumber2         = dbm.DataReaderValue("TelephoneNumber2") == DBNull.Value ? null : (string)dbm.DataReaderValue("TelephoneNumber2");
                settings.TwitterUsername          = dbm.DataReaderValue("TwitterUsername") == DBNull.Value ? null : (string)dbm.DataReaderValue("TwitterUsername");
                settings.YouTubeChannelId         = dbm.DataReaderValue("YouTubeChannelId") == DBNull.Value ? null : (string)dbm.DataReaderValue("YouTubeChannelId");
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }
Example #3
0
        public void Create(ContactSettings settings, IUnitOfWork unitOfWork = null)
        {
            IDatabaseManager dbm = _databaseManagerFactory.GetDatabaseManager(unitOfWork);

            try
            {
                dbm.SetSQL(_sqlManager.GetSql("Sql.CreateContact.sql"));
                dbm.AddParameter("@TenantId", FieldType.BigInt, settings.TenantId);
                dbm.AddParameter("@ElementId", FieldType.BigInt, settings.ElementId);
                dbm.AddParameter("@DisplayName", FieldType.NVarChar, ContactLengths.DisplayNameMaxLength, settings.DisplayName ?? (object)DBNull.Value);
                dbm.AddParameter("@Preamble", FieldType.NVarChar, -1, settings.Preamble ?? (object)DBNull.Value);
                dbm.AddParameter("@Address", FieldType.NVarChar, ContactLengths.AddressMaxLength, settings.Address ?? (object)DBNull.Value);
                dbm.AddParameter("@Email", FieldType.NVarChar, ContactLengths.EmailMaxLength, settings.Email ?? (object)DBNull.Value);
                dbm.AddParameter("@FacebookUsername", FieldType.NVarChar, ContactLengths.FacebookUsernameMaxLength, settings.FacebookUsername ?? (object)DBNull.Value);
                dbm.AddParameter("@InstagramUsername", FieldType.NVarChar, ContactLengths.InstagramUsernameMaxLength, settings.InstagramUsername ?? (object)DBNull.Value);
                dbm.AddParameter("@LinkedInCompanyUsername", FieldType.NVarChar, ContactLengths.LinkedInCompanyUsernameMaxLength, settings.LinkedInCompanyUsername ?? (object)DBNull.Value);
                dbm.AddParameter("@LinkedInPersonalUsername", FieldType.NVarChar, ContactLengths.LinkedInPersonalUsernameMaxLength, settings.LinkedInPersonalUsername ?? (object)DBNull.Value);
                dbm.AddParameter("@TelephoneNumber1", FieldType.NVarChar, ContactLengths.TelephoneNumber1MaxLength, settings.TelephoneNumber1 ?? (object)DBNull.Value);
                dbm.AddParameter("@TelephoneNumber2", FieldType.NVarChar, ContactLengths.TelephoneNumber2MaxLength, settings.TelephoneNumber2 ?? (object)DBNull.Value);
                dbm.AddParameter("@TwitterUsername", FieldType.NVarChar, ContactLengths.TwitterUsernameMaxLength, settings.TwitterUsername ?? (object)DBNull.Value);
                dbm.AddParameter("@YouTubeChannelId", FieldType.NVarChar, ContactLengths.YouTubeChannelIdMaxLength, settings.YouTubeChannelId ?? (object)DBNull.Value);
                dbm.ExecuteNonQuery();
            }
            finally
            {
                if (unitOfWork == null)
                {
                    dbm.Dispose();
                }
            }
        }
Example #4
0
        /// <summary>
        /// Submits form.
        /// </summary>
        /// <param name="form">View model containing form definition and submitted values.</param>
        /// <returns>Result of form post.</returns>
        public FormResult PostForm(Form form)
        {
            try
            {
                // Check permissions
                _authorizationService.AuthorizeUserForFunction(Functions.UpdatePageElements);

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

                // Get updated settings
                ContactSettings settings = (ContactSettings)New(_authenticationService.TenantId);
                settings.ElementId                = elementId;
                settings.DisplayName              = string.IsNullOrWhiteSpace(((TextField)form.Fields["displayName"]).Value) ? null : ((TextField)form.Fields["displayName"]).Value;
                settings.Preamble                 = string.IsNullOrWhiteSpace(((MultiLineTextField)form.Fields["preamble"]).Value) ? null : ((MultiLineTextField)form.Fields["preamble"]).Value;
                settings.Address                  = string.IsNullOrWhiteSpace(((TextField)form.Fields["address"]).Value) ? null : ((TextField)form.Fields["address"]).Value;
                settings.Email                    = string.IsNullOrWhiteSpace(((TextField)form.Fields["email"]).Value) ? null : ((TextField)form.Fields["email"]).Value;
                settings.FacebookUsername         = string.IsNullOrWhiteSpace(((TextField)form.Fields["facebookUsername"]).Value) ? null : ((TextField)form.Fields["facebookUsername"]).Value;
                settings.InstagramUsername        = string.IsNullOrWhiteSpace(((TextField)form.Fields["instagramUsername"]).Value) ? null : ((TextField)form.Fields["instagramUsername"]).Value;
                settings.LinkedInCompanyUsername  = string.IsNullOrWhiteSpace(((TextField)form.Fields["linkedInCompanyUsername"]).Value) ? null : ((TextField)form.Fields["linkedInCompanyUsername"]).Value;
                settings.LinkedInPersonalUsername = string.IsNullOrWhiteSpace(((TextField)form.Fields["linkedInPersonalUsername"]).Value) ? null : ((TextField)form.Fields["linkedInPersonalUsername"]).Value;
                settings.TelephoneNumber1         = string.IsNullOrWhiteSpace(((TextField)form.Fields["telephoneNumber1"]).Value) ? null : ((TextField)form.Fields["telephoneNumber1"]).Value;
                settings.TelephoneNumber2         = string.IsNullOrWhiteSpace(((TextField)form.Fields["telephoneNumber2"]).Value) ? null : ((TextField)form.Fields["telephoneNumber2"]).Value;
                settings.TwitterUsername          = string.IsNullOrWhiteSpace(((TextField)form.Fields["twitterUsername"]).Value) ? null : ((TextField)form.Fields["twitterUsername"]).Value;
                settings.YouTubeChannelId         = string.IsNullOrWhiteSpace(((TextField)form.Fields["youTubeChannelId"]).Value) ? null : ((TextField)form.Fields["youTubeChannelId"]).Value;

                // Perform the update
                Update(settings);

                // Return form result with no errors
                return(_formHelperService.GetFormResult());
            }
            catch (ValidationErrorException ex)
            {
                // Return form result containing errors
                return(_formHelperService.GetFormResultWithValidationErrors(ex.Errors));
            }
            catch (Exception)
            {
                // Return form result containing unexpected error message
                return(_formHelperService.GetFormResultWithErrorMessage(ApplicationResource.UnexpectedErrorMessage));
            }
        }
Example #5
0
        public Form GetForm(string context)
        {
            // Check permissions
            _authorizationService.AuthorizeUserForFunction(Functions.UpdatePageElements);

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

            // Get current settings
            Guid            elementTypeId = FormId;
            ContactSettings settings      = (ContactSettings)New(_authenticationService.TenantId);

            settings.ElementId = elementId;
            Read(settings);

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

            form.Fields.Add("displayName", new TextField {
                Name                  = "displayName",
                Label                 = ElementResource.ContactDisplayNameLabel,
                MaxLength             = ContactLengths.DisplayNameMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.ContactDisplayNameMaxLengthMessage, "displayName", ContactLengths.DisplayNameMaxLength),
                Value                 = settings.DisplayName
            });
            form.Fields.Add("preamble", new MultiLineTextField {
                Name  = "preamble",
                Label = ElementResource.ContactPreambleLabel,
                Value = settings.Preamble,
                Rows  = 4
            });
            form.Fields.Add("address", new TextField {
                Name                  = "address",
                Label                 = ElementResource.ContactAddressLabel,
                MaxLength             = ContactLengths.AddressMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.ContactAddressMaxLengthMessage, "address", ContactLengths.AddressMaxLength),
                Value                 = settings.Address
            });
            form.Fields.Add("email", new TextField {
                Name                  = "email",
                Label                 = ElementResource.ContactEmailLabel,
                MaxLength             = ContactLengths.EmailMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.ContactEmailMaxLengthMessage, "email", ContactLengths.EmailMaxLength),
                Value                 = settings.Email
            });
            form.Fields.Add("facebookUsername", new TextField {
                Name                  = "facebookUsername",
                Label                 = ElementResource.ContactFacebookUsernameLabel,
                MaxLength             = ContactLengths.FacebookUsernameMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.ContactFacebookUsernameMaxLengthMessage, "facebookUsername", ContactLengths.FacebookUsernameMaxLength),
                Value                 = settings.FacebookUsername
            });
            form.Fields.Add("instagramUsername", new TextField {
                Name                  = "instagramUsername",
                Label                 = ElementResource.ContactInstagramUsernameLabel,
                MaxLength             = ContactLengths.InstagramUsernameMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.ContactInstagramUsernameMaxLengthMessage, "instagramUsername", ContactLengths.InstagramUsernameMaxLength),
                Value                 = settings.InstagramUsername
            });
            form.Fields.Add("linkedInCompanyUsername", new TextField {
                Name                  = "linkedInCompanyUsername",
                Label                 = ElementResource.ContactLinkedInCompanyUsernameLabel,
                MaxLength             = ContactLengths.LinkedInCompanyUsernameMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.ContactLinkedInCompanyUsernameMaxLengthMessage, "linkedInCompanyUsername", ContactLengths.LinkedInCompanyUsernameMaxLength),
                Value                 = settings.LinkedInCompanyUsername
            });
            form.Fields.Add("linkedInPersonalUsername", new TextField {
                Name                  = "linkedInPersonalUsername",
                Label                 = ElementResource.ContactLinkedInPersonalUsernameLabel,
                MaxLength             = ContactLengths.LinkedInPersonalUsernameMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.ContactLinkedInPersonalUsernameMaxLengthMessage, "linkedInPersonalUsername", ContactLengths.LinkedInPersonalUsernameMaxLength),
                Value                 = settings.LinkedInPersonalUsername
            });
            form.Fields.Add("telephoneNumber1", new TextField {
                Name                  = "telephoneNumber1",
                Label                 = ElementResource.ContactTelephoneNumber1Label,
                MaxLength             = ContactLengths.TelephoneNumber1MaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.ContactTelephoneNumber1MaxLengthMessage, "telephoneNumber1", ContactLengths.TelephoneNumber1MaxLength),
                Value                 = settings.TelephoneNumber1
            });
            form.Fields.Add("telephoneNumber2", new TextField {
                Name                  = "telephoneNumber2",
                Label                 = ElementResource.ContactTelephoneNumber2Label,
                MaxLength             = ContactLengths.TelephoneNumber2MaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.ContactTelephoneNumber2MaxLengthMessage, "telephoneNumber2", ContactLengths.TelephoneNumber2MaxLength),
                Value                 = settings.TelephoneNumber2
            });
            form.Fields.Add("twitterUsername", new TextField {
                Name                  = "twitterUsername",
                Label                 = ElementResource.ContactTwitterUsernameLabel,
                MaxLength             = ContactLengths.TwitterUsernameMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.ContactTwitterUsernameMaxLengthMessage, "twitterUsername", ContactLengths.TwitterUsernameMaxLength),
                Value                 = settings.TwitterUsername
            });
            form.Fields.Add("youTubeChannelId", new TextField {
                Name                  = "youTubeChannelId",
                Label                 = ElementResource.ContactYouTubeChannelIdLabel,
                MaxLength             = ContactLengths.YouTubeChannelIdMaxLength,
                MaxLengthErrorMessage = string.Format(ElementResource.ContactYouTubeChannelIdMaxLengthMessage, "youTubeChannelId", ContactLengths.YouTubeChannelIdMaxLength),
                Value                 = settings.YouTubeChannelId
            });
            form.SubmitLabel = ElementResource.ContactButtonLabel;

            // Return result
            return(form);
        }