Пример #1
0
        private void FormsEvents_FormsSubmissionFinalized(object sender, FormsEventArgs e)
        {
            if (!string.IsNullOrEmpty(e.FormsContent.Name))
            {
                var loader = ServiceLocator.Current.GetInstance <IContentLoader>();
                FormsSubmittedEventArgs submitArgs = e as FormsSubmittedEventArgs;
                string msg = string.Format("Form {0} completed at {1}\tSubmission id: {2}",
                                           e.FormsContent.Name,
                                           DateTime.Now,
                                           submitArgs.SubmissionData.Id);
                _logger.Information(msg);

                var formElements = submitArgs.FormsContent.Property["ElementsArea"].Value as ContentArea;

                foreach (var item in submitArgs.SubmissionData.Data)
                {
                    if (item.Key.StartsWith("SYSTEM"))
                    {
                        _logger.Information(item.Key + ": " + item.Value);
                    }
                    else
                    {
                        int id                        = Convert.ToInt32(item.Key.Substring(item.Key.LastIndexOf("_") + 1));
                        var elementId                 = formElements.Items.Where(i => i.ContentLink.ID == id).FirstOrDefault();
                        ElementBlockBase element      = loader.Get <ElementBlockBase>(elementId.ContentLink) as ElementBlockBase;
                        string           friendlyName = element != null?element.GetElementInfo().FriendlyName : item.Key;

                        _logger.Information(friendlyName + ": " + item.Value);
                    }
                }
            }
        }
        /// <summary>
        /// Returns a list of suggested values by field mapping key. This will be called automatically by the GetAutofillValues() function in DataElementBlockBase for each field
        /// </summary>
        /// <returns>Collection of suggested values</returns>
        public virtual IEnumerable <string> GetSuggestedValues(IDatasource selectedDatasource, IEnumerable <RemoteFieldInfo> remoteFieldInfos, ElementBlockBase content, IFormContainerBlock formContainerBlock, HttpContextBase context)
        {
            if (selectedDatasource == null || remoteFieldInfos == null)
            {
                return(Enumerable.Empty <string>());
            }

            // Make sure the Data sources are for this system
            if (!this.Datasources.Any(ds => ds.Id == selectedDatasource.Id) ||
                !remoteFieldInfos.Any(mi => mi.DatasourceId == selectedDatasource.Id))
            {
                return(Enumerable.Empty <string>());
            }

            // We also need to make sure that we have some tracking info to auto fill
            // _madid is the default Episerver Profile Store tracking cookie, see https://world.episerver.com/documentation/developer-guides/tracking/episerver-cookies/
            var userDeviceId = context.Request.Cookies["_madid"]?.Value;

            // Because this gets called with EVERY FIELD it is suggested to cache the response elsewhere
            var userProfile = ProfileStoreApiService.GetProfileByDeviceId(userDeviceId);

            if (userProfile == null)
            {
                return(Enumerable.Empty <string>());
            }

            // Unpack the info object
            var info = userProfile["Info"];

            // Get the field details
            var activeRemoteFieldInfo = remoteFieldInfos.FirstOrDefault(mi => mi.DatasourceId == selectedDatasource.Id);

            switch (activeRemoteFieldInfo.ColumnId)
            {
            // Suggest the data from the Profile Store user profile
            case "profilestoreemail":
                return(new List <string> {
                    (string)(info["Email"] ?? info["Email"]?.ToString())
                });

            case "profilestorename":
                return(new List <string> {
                    (string)(userProfile["Name"] ?? userProfile["Name"]?.ToString())
                });

            case "profilestorecity":
                return(new List <string> {
                    (string)(info["City"] ?? info["City"]?.ToString())
                });

            case "profilestorephone":
                return(new List <string> {
                    (string)(info["Phone"] ?? info["Phone"]?.ToString())
                });

            case "profilestoremobile":
                return(new List <string> {
                    (string)(info["Mobile"] ?? info["Mobile"]?.ToString())
                });

            default:
                return(Enumerable.Empty <string>());
            }
        }