public override ActionResult Index(FormContainerBlock currentBlock)
 {
     var rep = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();
     currentBlock = currentBlock.CreateWritableClone() as FormContainerBlock;
     string eventPage = "";
     if (this.ControllerContext.ParentActionViewContext.ViewData["EventPage"] != null)
     {
         eventPage = this.ControllerContext.ParentActionViewContext.ViewData["EventPage"].ToString();
     }
     if(string.IsNullOrEmpty(eventPage) == false)
     { 
         var attendSessionFormType = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentTypeRepository>().Load<AttendSessionForm>();
         foreach (var element in currentBlock.ElementsArea.Items)
         {
             var elementData = rep.Get<IContent>(element.ContentLink);
             if((elementData as AttendSessionForm) != null)
             {
                 (elementData as AttendSessionForm).Sessions = BVNetwork.Attend.Business.API.AttendSessionEngine.GetSessionsList(new ContentReference(eventPage));
                 (elementData as AttendSessionForm).EventName = "Temp";
             }
         }
         currentBlock.RedirectToPage = new EPiServer.Url(eventPage);
     }
     var baseActionResult = base.Index(currentBlock);
     return baseActionResult;
 }
        public static void RenderFormElements(this HtmlHelper html, int currentStepIndex, IEnumerable<IFormElement> elements, FormContainerBlock model)
        {
            // TODO: this is pretty scary - another approach would be to ask from container and then try to cast to this type..
            var renderer = new BootstrapAwareContentAreaRenderer();

            foreach (var element in elements)
            {
                var areaItem = model.ElementsArea.Items.FirstOrDefault(i => i.ContentLink == element.SourceContent.ContentLink);

                if(areaItem != null)
                {
                    var cssClasses = renderer.GetItemCssClass(html, areaItem);
                    html.ViewContext.Writer.Write($"<div class=\"{cssClasses}\">");
                }

                var sourceContent = element.SourceContent;
                if((sourceContent != null) && !sourceContent.IsDeleted)
                {
                    if(sourceContent is ISubmissionAwareElement)
                    {
                        var content2 = (sourceContent as IReadOnly).CreateWritableClone() as IContent;
                        (content2 as ISubmissionAwareElement).FormSubmissionId = (string) html.ViewBag.FormSubmissionId;
                        html.RenderContentData(content2, false);
                    }
                    else
                    {
                        html.RenderContentData(sourceContent, false);
                    }
                }

                if(areaItem != null)
                    html.ViewContext.Writer.Write("</div>");
            }
        }
        private Dictionary <string, string> GetMappedProfileFields(FormContainerBlock formContainerBlock)
        {
            var results = new Dictionary <string, string>();

            if (formContainerBlock?.ElementsArea?.Items != null && (formContainerBlock.ElementsArea.Items.Count != 0))
            {
                var allElements = formContainerBlock.ElementsArea.Items;
                foreach (var formElement in allElements)
                {
                    var formItem = _contentRepo.Service.Get <ElementBlockBase>(formElement.ContentLink,
                                                                               (formContainerBlock as ILocale)?.Language);

                    if (formItem?.Property[FormToInsightMappingInit.InsightProfileMappingPropertyName]?.Value != null)
                    {
                        var insightPropertyName = formItem
                                                  .Property[FormToInsightMappingInit.InsightProfileMappingPropertyName].Value.ToString();
                        if (!string.IsNullOrEmpty(insightPropertyName))
                        {
                            var formContent = formItem as IContent;
                            results.Add(formContent.Name, insightPropertyName);
                        }
                    }
                }
            }

            return(results);
        }
示例#4
0
        private void FormsEvents_FormsSubmitting(object sender, FormsEventArgs e)
        {
            FormsSubmittingEventArgs formsSubmitEvents = e as FormsSubmittingEventArgs;
            NameValueCollection      rawFormData       = formsSubmitEvents.Data as NameValueCollection;
            FormContainerBlock       formBlock         = formsSubmitEvents.FormsContent as FormContainerBlock;
            Submission submissionData = formsSubmitEvents.SubmissionData;

            FormParser.ProcessForm(rawFormData, formBlock, submissionData);
        }
示例#5
0
        private bool IsValidationFail(FormContainerBlock currentBlock, Guid expectedFormGuid)
        {
            bool flag;

            if ((currentBlock.Form.FormGuid != expectedFormGuid) || IsSuccess())
            {
                return(false);
            }
            bool.TryParse(this.GetParamValue("__ValidationFail"), out flag);
            return(flag);
        }
示例#6
0
        private bool IsFormFinalized(FormContainerBlock currentBlock, Guid expectedFormGuid)
        {
            bool flag;

            if ((currentBlock.Form.FormGuid != expectedFormGuid) || !IsSuccess())
            {
                return(false);
            }
            bool.TryParse(this.GetParamValue("__FormFinalized"), out flag);
            return(flag);
        }
 public ActionResult Index(FormContainerBlock currentBlock)
 {
     currentBlock = currentBlock.CreateWritableClone() as FormContainerBlock;
     string eventPage = "";
     if (this.ControllerContext.ParentActionViewContext.ViewData["EventPage"] != null)
     {
         eventPage = this.ControllerContext.ParentActionViewContext.ViewData["EventPage"].ToString();
     }
     currentBlock.RedirectToPage = new EPiServer.Url(eventPage);
     var baseActionResult = base.Index(currentBlock);
     return baseActionResult;
 }
示例#8
0
        public ActionResult Index(FormContainerBlock currentBlock)
        {
            currentBlock = currentBlock.CreateWritableClone() as FormContainerBlock;
            string eventPage = "";

            if (this.ControllerContext.ParentActionViewContext.ViewData["EventPage"] != null)
            {
                eventPage = this.ControllerContext.ParentActionViewContext.ViewData["EventPage"].ToString();
            }
            currentBlock.RedirectToPage = new EPiServer.Url(eventPage);
            var baseActionResult = base.Index(currentBlock);

            return(baseActionResult);
        }
        public static void RenderFormElements(
            this HtmlHelper html,
            int currentStepIndex,
            IEnumerable <IFormElement> elements,
            FormContainerBlock model,
            object additionalValues = null)
        {
            // this means that somebody else took renderer seat and we need to find way around it
            // essentially the only thing that is needed is access to renderer instance - we can create one from scratch here also
            var renderer = ServiceLocator.Current.GetInstance <ContentAreaRenderer>() as BootstrapAwareContentAreaRenderer
                           ?? new BootstrapAwareContentAreaRenderer(SetupBootstrapRenderer.AllDisplayOptions);

            var additionalParameters = new RouteValueDictionary(additionalValues);

            var isRowSupported = additionalParameters.GetValueFromDictionary("rowsupport");
            var addRowMarkup   = ConfigurationContext.Current.RowSupportEnabled && isRowSupported.HasValue && isRowSupported.Value;

            if (!addRowMarkup)
            {
                foreach (var element in elements)
                {
                    var areaItem = model
                                   .ElementsArea
                                   .Items
                                   .FirstOrDefault(i => i.ContentLink == element.SourceContent.ContentLink);

                    RenderAreaItem(html, areaItem, renderer, element);
                }
            }
            else
            {
                var rowRenderer = new RowRenderer();
                rowRenderer.Render(
                    model.ElementsArea.Items,
                    html,
                    renderer.ContentAreaItemTemplateTagCore,
                    renderer.GetColumnWidth,
                    (_, items) => RenderItems(html, items, renderer, elements));
            }
        }
示例#10
0
        public static NameValueCollection ParseForm(Submission submission, FormContainerBlock formContainer)
        {
            NameValueCollection formData = new NameValueCollection();
            IContentRepository  rep      = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance <IContentRepository>();
            string email = string.Empty;

            foreach (var element in formContainer.ElementsArea.Items)
            {
                bool   skip    = false;
                var    control = rep.Get <IContent>(element.ContentLink);
                string value   = string.Empty;
                string key     = "__field_" + control.ContentLink.ID.ToString();
                if (submission.Data.ContainsKey(key))
                {
                    var elementObject = submission.Data[key];
                    if (elementObject != null)
                    {
                        value = elementObject.ToString();
                        if (new [] { "email", "e-mail", "epost", "e-post" }.Contains(control.Name.ToLower()))
                        {
                            formData.Add(__AttendEmail, value);
                            skip = true;
                        }
                        if (control as AttendSessionForm != null)
                        {
                            formData.Add(__AttendSessions, value);
                            skip = true;
                        }
                    }
                    if (!skip)
                    {
                        formData.Add(control.Name, value);
                    }
                }
            }
            return(formData);
        }
示例#11
0
        public static List <Submission> GetComment()
        {
            Injected <IFormRepository> _formRepository     = new Injected <IFormRepository>();
            List <Submission>          submittedData       = new List <Submission>();
            FormDataRepository         _formDataRepository = new FormDataRepository();


            FormContainerBlock _formContainerBlock = new FormContainerBlock();

            List <Submission> submittedDataBlock = new List <Submission>();

            var formsInfo = _formRepository.Service.GetFormsInfo(null);


            foreach (var info in formsInfo)
            {
                submittedData = _formDataRepository.GetSubmissionData(
                    new FormIdentity(info.FormGuid, "en"),
                    DateTime.Now.AddDays(-100),
                    DateTime.Now).ToList();
            }

            return(submittedData);
        }
示例#12
0
        public static void ProcessForm(NameValueCollection rawFormData, FormContainerBlock formBlock, Submission submissionData)
        {
            string        eventPageIds     = rawFormData[__AttendEvent];
            string        participantEmail = rawFormData[__AttendParticipantEmail];
            string        participantCode  = rawFormData[__AttendParticipantCode];
            List <string> eventPages       = null;

            if (string.IsNullOrEmpty(eventPageIds)) // Not an Attend form - exit form processing.
            {
                return;
            }
            if (eventPageIds.Split(',').Length > 1)
            {
                eventPages = eventPageIds.Split(',').ToList <string>();
            }
            else
            {
                eventPages = new List <string>()
                {
                    eventPageIds
                }
            };

            SetPrivatePropertyValue <PropertyData>(false, "IsReadOnly", formBlock.Property["SubmitSuccessMessage"]);

            NameValueCollection nvc     = FormParser.ParseForm(submissionData, formBlock);
            StringBuilder       message = new StringBuilder();
            StringBuilder       codes   = new StringBuilder();

            foreach (string eventPageId in eventPages)
            {
                ContentReference eventPage     = new ContentReference(eventPageId).ToPageReference();
                EventPageBase    eventPageBase = ServiceLocator.Current.GetInstance <IContentRepository>().Get <EventPageBase>(eventPage);

                if (eventPages.Count > 1)
                {
                    message.Append("<strong>" + eventPageBase.Name + "</strong><br/>");
                }

                IParticipant participant = null;
                if (!string.IsNullOrEmpty(participantCode) && !string.IsNullOrEmpty(participantEmail))
                {
                    participant = BVNetwork.Attend.Business.API.AttendRegistrationEngine.GetParticipant(participantEmail, participantCode);
                    participant = FormParser.UpdateParticipation(participant, nvc);
                }
                if (participant == null)
                {
                    participant = FormParser.GenerateParticipation(eventPage, nvc);
                }


                if (participant.AttendStatus == AttendStatus.Confirmed.ToString())
                {
                    if (eventPageBase.CompleteContentXhtml != null)
                    {
                        message.Append(eventPageBase.CompleteContentXhtml.ToHtmlString());
                    }
                    else
                    {
                        message.Append(EPiServer.Framework.Localization.LocalizationService.Current.GetString("/eventRegistrationPage/confirmed"));
                    }
                }

                if (participant.AttendStatus == AttendStatus.Submitted.ToString())
                {
                    if (eventPageBase.SubmittedContentXhtml != null)
                    {
                        message.Append(eventPageBase.SubmittedContentXhtml.ToHtmlString());
                    }
                    else
                    {
                        message.Append(EPiServer.Framework.Localization.LocalizationService.Current.GetString("/eventRegistrationPage/submitted"));
                    }
                }
                if (message.Length == 0)
                {
                    message.Append(EPiServer.Framework.Localization.LocalizationService.Current.GetString("/eventRegistrationPage/error"));
                }
                message.Append("<br/><br/>");
                codes.Append(participant.Code + ",");
            }

            if (formBlock.RedirectToPage != null)
            {
                SetPrivatePropertyValue <PropertyData>(false, "IsReadOnly", formBlock.Property["RedirectToPage"]);
                Url redirectUrl = new Url(formBlock.RedirectToPage.Uri.ToString() + "?code=" + codes.ToString() + "&eventPageID=" + eventPageIds);
                formBlock.RedirectToPage = redirectUrl;
            }
            formBlock.SubmitSuccessMessage = new XhtmlString(message.ToString());
        }
        public override ActionResult Index(FormContainerBlock currentBlock)
        {
            var    rep   = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance <IContentRepository>();
            string email = Request.QueryString["email"];
            string code  = Request.QueryString["code"];


            currentBlock = currentBlock.CreateWritableClone() as FormContainerBlock;
            string eventPage = "";

            if (this.ControllerContext.ParentActionViewContext.ViewData["EventPage"] != null)
            {
                eventPage = this.ControllerContext.ParentActionViewContext.ViewData["EventPage"].ToString();
            }
            if (string.IsNullOrEmpty(eventPage) == false)
            {
                foreach (var element in currentBlock.ElementsArea.Items)
                {
                    var elementData = rep.Get <IContent>(element.ContentLink);
                    if ((elementData as AttendSessionForm) != null)
                    {
                        (elementData as AttendSessionForm).Sessions  = BVNetwork.Attend.Business.API.AttendSessionEngine.GetSessionsList(new ContentReference(eventPage));
                        (elementData as AttendSessionForm).EventName = "Temp";
                    }
                }
                currentBlock.RedirectToPage = new EPiServer.Url(eventPage);
            }

            // Edit existing participation?
            var currentParticipant = BVNetwork.Attend.Business.API.AttendRegistrationEngine.GetParticipant(email, code);

            if (currentParticipant != null)
            {
                AttendSubmitButton          submitButton     = null;
                Dictionary <string, string> predefinedValues = new Dictionary <string, string>();
                foreach (var element in currentBlock.ElementsArea.Items)
                {
                    var    elementData = rep.Get <IContent>(element.ContentLink);
                    string value       = BVNetwork.Attend.Business.API.AttendRegistrationEngine.GetParticipantInfo(currentParticipant, elementData.Name);
                    if (!string.IsNullOrEmpty(value))
                    {
                        predefinedValues.Add(elementData.GetType().Name + ";__field_" + element.ContentLink.ID, value);
                    }
                    if ((elementData as AttendSubmitButton) != null)
                    {
                        submitButton = elementData as AttendSubmitButton;
                    }
                }
                if (submitButton != null)
                {
                    submitButton.PredefinedValues = predefinedValues;
                    submitButton.ParticipantCode  = currentParticipant.Code;
                    submitButton.ParticipantEmail = currentParticipant.Email;
                }
            }


            var baseActionResult = base.Index(currentBlock);

            return(baseActionResult);
        }
示例#14
0
        public static void RenderFormElements(this HtmlHelper html, int currentStepIndex, IEnumerable <IFormElement> elements, FormContainerBlock model)
        {
            // TODO: this is pretty scary - another approach would be to ask from container and then try to cast to this type..
            var renderer = new BootstrapAwareContentAreaRenderer();

            foreach (var element in elements)
            {
                var areaItem = model.ElementsArea.Items.FirstOrDefault(i => i.ContentLink == element.SourceContent.ContentLink);

                if (areaItem != null)
                {
                    var cssClasses = renderer.GetItemCssClass(html, areaItem);
                    html.ViewContext.Writer.Write($"<div class=\"{cssClasses}\">");
                }

                var sourceContent = element.SourceContent;
                if ((sourceContent != null) && !sourceContent.IsDeleted)
                {
                    if (sourceContent is ISubmissionAwareElement)
                    {
                        var content2 = (sourceContent as IReadOnly).CreateWritableClone() as IContent;
                        (content2 as ISubmissionAwareElement).FormSubmissionId = (string)html.ViewBag.FormSubmissionId;
                        html.RenderContentData(content2, false);
                    }
                    else
                    {
                        html.RenderContentData(sourceContent, false);
                    }
                }

                if (areaItem != null)
                {
                    html.ViewContext.Writer.Write("</div>");
                }
            }
        }
示例#15
0
        public static void RenderFormElements(this HtmlHelper html, int currentStepIndex, IEnumerable <IFormElement> elements, FormContainerBlock model)
        {
            var renderer =
                ServiceLocator.Current.GetInstance <ContentAreaRenderer>() as BootstrapAwareContentAreaRenderer ??
                throw new InvalidOperationException("Registered `ContentAreaRenderer` in IoC is not of type `BootstrapAwareContentAreaRenderer`. Verify that you have correct renderer registered.");

            foreach (var element in elements)
            {
                var areaItem = model.ElementsArea.Items.FirstOrDefault(i => i.ContentLink == element.SourceContent.ContentLink);

                if (areaItem != null)
                {
                    var cssClasses = renderer.GetItemCssClass(html, areaItem);
                    html.ViewContext.Writer.Write($"<div class=\"{cssClasses}\">");
                }

                var sourceContent = element.SourceContent;
                if (sourceContent != null && !sourceContent.IsDeleted)
                {
                    if (sourceContent is ISubmissionAwareElement)
                    {
                        var contentData = (sourceContent as IReadOnly).CreateWritableClone() as IContent;
                        (contentData as ISubmissionAwareElement).FormSubmissionId = (string)html.ViewBag.FormSubmissionId;
                        html.RenderContentData(contentData, false);
                    }
                    else
                    {
                        html.RenderContentData(sourceContent, false);
                    }
                }

                if (areaItem != null)
                {
                    html.ViewContext.Writer.Write("</div>");
                }
            }
        }
        public override string Execute()
        {
            OnStatusChanged(string.Format(
                                "Starting execution of {0}", this.GetType()));

            var finder = ServiceLocator.Current
                         .GetInstance <IPageCriteriaQueryService>();

            var language = Thread.CurrentThread.CurrentCulture.Name.Substring(0, 2);

            var criteria = new PropertyCriteriaCollection();

            if (language == "en")
            {
                criteria.Add(new PropertyCriteria
                {
                    Type      = PropertyDataType.LongString,
                    Name      = "PageName",
                    Condition = EPiServer.Filters.CompareCondition.Equal,
                    Value     = "Services"
                });
            }
            else if (language == "sv")
            {
                criteria.Add(new PropertyCriteria
                {
                    Type      = PropertyDataType.LongString,
                    Name      = "PageName",
                    Condition = EPiServer.Filters.CompareCondition.Equal,
                    Value     = "Tjänster"
                });
            }
            else
            {
                throw new InvalidOperationException($"No suppor for language branch: {language}");
            }

            var servicesPage = finder.FindPagesWithCriteria(
                ContentReference.RootPage as PageReference, criteria, language)[0] as ServicesPage;

            var loader = ServiceLocator.Current.GetInstance <IContentLoader>();

            if (servicesPage != null && servicesPage.MainContentArea != null && servicesPage.MainContentArea.Items.Any())
            {
                int count = 0;
                FormContainerBlock formContainerBlock = null;

                foreach (var item in servicesPage.MainContentArea.Items)
                {
                    try
                    {
                        formContainerBlock = loader.Get <FormContainerBlock>(item.ContentLink);
                    }
                    catch (TypeMismatchException)
                    {
                        if (count >= servicesPage.MainContentArea.Items.Count)
                        {
                            throw;
                        }
                    }
                    if (_stopSignaled)
                    {
                        return("Stop of job was called");
                    }
                    count++;
                }

                if (formContainerBlock != null)
                {
                    var formDataRepository = ServiceLocator.Current.GetInstance <IFormDataRepository>();

                    List <Submission> submittedData = formDataRepository.GetSubmissionData(
                        new FormIdentity(formContainerBlock.Form.FormGuid, servicesPage.Language.Name),
                        DateTime.Now.AddDays(-100), DateTime.Now)
                                                      .ToList();

                    if (submittedData.Count > 0)
                    {
                        var repo       = ServiceLocator.Current.GetInstance <IContentRepository>();
                        var clone      = servicesPage.CreateWritableClone() as ServicesPage;
                        var editString = servicesPage.MainBody.ToHtmlString();
                        int length     = editString.IndexOf("<div id=\"newsletter-receivers\">");

                        editString  = editString.Substring(0, length == -1 ? editString.Length : length);
                        editString += "<div id=\"newsletter-receivers\"><ul style='color:black;'>";
                        count       = 0;

                        foreach (var submission in submittedData)
                        {
                            string email;
                            if (language == "en")
                            {
                                email = submission.Data["__field_40"] as string;
                            }
                            else
                            {
                                email = submission.Data["__field_36"] as string;
                            }

                            editString += $"<li>{email}</li>";
                            if (_stopSignaled)
                            {
                                return("Stop of job was called");
                            }
                            count++;
                        }
                        editString    += "</ul></div>";
                        clone.MainBody = new XhtmlString(editString);
                        repo.Save(clone, EPiServer.DataAccess.SaveAction.CheckIn,
                                  EPiServer.Security.AccessLevel.NoAccess);

                        return($"The newsletter receivers list on the services-page has been updated and now contains {count} customer(s) in total.");
                    }
                    return("No submitted data was found");
                }
                return("No form container block was found");
            }
            return("No services page with the page name: 'Services' was found or services page was found but MainContentArea was empty.");
        }