Try our conversational search powered by Generative AI!

ProfileService.cs

Version InfoThis topic applies to Episerver.ConnectForMarketingAutomation 4.0.0 and lower. For later versions, see Sample Connector - IMarketingConnector

using System.Collections.Generic;
using EPiServer.MarketingAutomationIntegration.Domain;
using EPiServer.MarketingAutomationIntegration.Services;

namespace DemoConnector.Services
{
    /// <summary>
    /// Interface for working with profiles.
    /// </summary>
    /// <remarks>
    /// If you do not want to support profiles, GetCurrentProfileFromSource should throw NotImplementedException. 
    /// </remarks>
    public class ProfileService : IProfileService
    {
        /// <summary>
        /// Adds the profile to the profile list.
        /// </summary>
        /// <param name="listId">The list identifier.</param>
        /// <param name="profileId">The profile identifier.</param>
        /// <returns>Result of adding the profile to the list.</returns>
        public bool AddProfileToList(int listId, long profileId)
        {
            return true;
        }

        /// <summary>
        /// Create a new profile and add it to a database that the profile expects.
        /// </summary>
        /// <param name="newProfile">The new profile data.</param>
        /// <returns>The profile's Id string (null if not found).</returns>
        public string CreateProfile(Profile newProfile)
        {
            return int.MaxValue.ToString();
        }

        /// <summary>
        /// Go through sources and get the current profile.
        /// </summary>
        /// <returns>The current profile.</returns>
        public Profile GetCurrentProfile()
        {
            return new Profile()
            {
                Id = int.MaxValue,
                Email = "xyz@google.com",
                Columns = new Dictionary<string, object>() { }
            };
        }

        /// <summary>
        /// Get the current profile from the database Id.
        /// </summary>
        /// <param name="databaseId">Always int.Min</param>
        /// <returns>The current profile from the source.</returns>
        public Profile GetCurrentProfileFromSource(int databaseId)
        {
            Dictionary<string, object> dictionary = new Dictionary<string, object>();
            dictionary.Add("Column1", "yup");
            return new Profile() { Id = 1111, Email="fred@google.com", Columns = dictionary };
        }

       /// <summary>
        /// Gets a profile by Id.
        /// </summary>
        /// <param name="databaseId">The database Id.</param>
        /// <param name="profileId">The profile identifier.</param>
        /// <returns>
        /// A profile (null, if not found).
        /// </returns>
        public Profile GetProfile(int databaseId, long profileId)
        {
            return GetCurrentProfileFromSource(databaseId);
        }

        /// <summary>
        /// Opt-in a profile.
        /// </summary>
        /// <param name="databaseId">The database identifier.</param>
        /// <param name="profileId">The profile identifier.</param>
        /// <returns>
        /// True if opt-in is successful, (otherwise false).
        /// </returns>
        public bool OptInProfile(int databaseId, long profileId)
        {
            return true;
        }

        /// <summary>
        /// Opt-out a profile.
        /// </summary>
        /// <param name="databaseId">The database identifier.</param>
        /// <param name="profileId">The profile identifier.</param>
        /// <returns>
        /// True if opt-out is successful, (otherwise false).
        /// </returns>
        public bool OptOutProfile(int databaseId, long profileId)
        {
            return true;
        }

        /// <summary>
        /// Remove profile from the input database.
        /// </summary>
        /// <param name="databaseId">The database identifier.</param>
        /// <param name="profileId">The profile identifier.</param>
        /// <returns>
        /// True if removal is successful, (otherwise false).
        /// </returns>
        public bool RemoveProfile(int databaseId, long profileId)
        {
            return true;
        }

        /// <summary>
        /// Update a profile with input fields need to update.
        /// </summary>
        /// <param name="databaseId">The database identifier.</param>
        /// <param name="profileId">The profile identifier.</param>
        /// <param name="fieldsToUpdate">Dictionary of fields need to update.</param>
        /// <param name="addMissingColumns">if set to <c>true</c>, synchronize columns with the database.</param>
        /// <returns>True if update is successful, (otherwise false).</returns>
        public bool UpdateProfile(int databaseId, long profileId, Dictionary<string, object> fieldsToUpdate, bool addMissingColumns)
        {
            return true;
        }
    }
}

Related topics

Last updated: Dec 14, 2015