public async Task Generate(PlanTemplateCM planTemplate, string fr8AccountId)
        {
            var storage = await _tagGenerator.GetTags(planTemplate, fr8AccountId);

            foreach (var tag in storage.WebServiceTemplateTags)
            {
                var tags           = tag.TagsWithIcons.Select(x => x.Key).ToArray();
                var pageName       = GeneratePageNameFromTags(tags);
                var pageDefinition = _pageDefinitionService.Get(x => x.PageName == pageName && x.Type == PageType).FirstOrDefault() ?? new PageDefinitionDO
                {
                    PageName = pageName,
                    Tags     = tags,
                    Type     = PageType,
                    Title    = tag.Title
                };
                if (!pageDefinition.PlanTemplatesIds.Contains(planTemplate.ParentPlanId))
                {
                    pageDefinition.PlanTemplatesIds.Add(planTemplate.ParentPlanId);
                }
                pageDefinition.Url = new Uri($"{_templateGenerator.BaseUrl}/{pageName}");
                _pageDefinitionService.CreateOrUpdate(pageDefinition);
                var relatedPageDefinitions = _pageDefinitionService.GetAll().Where(x => x.PlanTemplatesIds.Contains(planTemplate.ParentPlanId));
                var curPageDefinition      = relatedPageDefinitions.FirstOrDefault(x => x.PageName == pageName);
                var curRelatedPlans        = new List <PublishPlanTemplateDTO>();
                foreach (var planTemplateId in curPageDefinition.PlanTemplatesIds)
                {
                    var planDto = _planTemplateService.GetPlanTemplateDTO(fr8AccountId, Guid.Parse(planTemplateId)).Result;
                    if (planDto != null)
                    {
                        curRelatedPlans.Add(planDto);
                    }
                }
                var relatedPlans = new List <Tuple <string, string, string> >();
                foreach (var publishPlanTemplateDTO in curRelatedPlans)
                {
                    relatedPlans.Add(new
                                     Tuple <string, string, string>(
                                         publishPlanTemplateDTO.Name,
                                         publishPlanTemplateDTO.Description ?? publishPlanTemplateDTO.Name,
                                         CloudConfigurationManager.GetSetting("HubApiUrl") +
                                         "plan_templates/createplan/?id=" + publishPlanTemplateDTO.ParentPlanId));
                }
                await _templateGenerator.Generate(new PlanCategoryTemplate(), pageName, new Dictionary <string, object>
                {
                    ["Name"]         = pageName,
                    ["Tags"]         = tag.TagsWithIcons,
                    ["RelatedPlans"] = relatedPlans
                });
            }
        }
Example #2
0
        public IEnumerable <PageDefinitionDTO> Get()
        {
            var pageDefinitions = _pageDefinition.GetAll();

            return(Mapper.Map <IList <PageDefinitionDTO> >(pageDefinitions));
        }