private void PopulateForm() { var credentialsStore = GcDynamicCredentials.RetrieveStore(); if (credentialsStore.IsNullOrEmpty()) { return; } txtEmailAddress.Text = credentialsStore.ToList().First().Email; txtApiKey.Text = credentialsStore.ToList().First().ApiKey; _client = new GcConnectClient(credentialsStore.ToList().First().ApiKey, credentialsStore.ToList().First().Email); var accounts = _client.GetAccounts(); accounts.ToList().ForEach(i => ddlGcAccounts.Items.Add(new ListItem(i.Name, i.Id))); if (!credentialsStore.ToList().First().AccountId.IsNullOrEmpty()) { ddlGcAccounts.SelectedValue = credentialsStore.ToList().First().AccountId; //txtPlatformUrl.Text = $"https://{_client.GetAccountById(Convert.ToInt32(credentialsStore.ToList().First().AccountId)).Slug}.gathercontent.com"; } else { ddlGcAccounts.SelectedIndex = 0; //txtPlatformUrl.Text = $"https://{_client.GetAccountById(Convert.ToInt32(ddlGcAccounts.SelectedValue)).Slug}.gathercontent.com"; } }
protected void BtnSave_OnClick(object sender, EventArgs e) { _credentialsStore = GcDynamicUtilities.RetrieveStore <GcDynamicCredentials>(); var apiKey = txtApiKey.Text; var emailAddress = txtEmailAddress.Text; _client = new GcConnectClient(apiKey, emailAddress); if (!_client.GetAccounts().IsNullOrEmpty()) { var selectedAccount = Request.Form["ddlGcAccounts"]; if (selectedAccount.IsNullOrEmpty()) { selectedAccount = _client.GetAccounts().ToList().First().Id; } _credentials = new GcDynamicCredentials(emailAddress, apiKey, selectedAccount); GcDynamicUtilities.SaveStore(_credentials); Response.Write($"<script>alert('Hello {_client.GetMe().FirstName}! You have successfully connected to" + " the GatherContent API')</script>"); } else { Response.Write("<script>alert('Invalid Email Address or ApiKey! Try again!')</script>"); //txtPlatformUrl.Text = ""; GcDynamicUtilities.ClearStore <GcDynamicCredentials>(); } PopulateForm(); }
private void PopulateForm() { var credentialsStore = GcDynamicCredentials.RetrieveStore(); if (credentialsStore.IsNullOrEmpty()) { Response.Write("<script>alert('Please setup your GatherContent config first!');window.location='/modules/GatherContentImport/GatherContent.aspx'</script>"); Visible = false; return; } if (Session["ProjectId"] == null) { Response.Write("<script>alert('Please select the GatherContent Project!');window.location='/modules/GatherContentImport/NewGcMappingStep1.aspx'</script>"); Visible = false; return; } _client = new GcConnectClient(credentialsStore.ToList().First().ApiKey, credentialsStore.ToList().First().Email); var projectId = Convert.ToInt32(Session["ProjectId"]); projectName.Text = _client.GetProjectById(projectId).Name; var templates = _client.GetTemplatesByProjectId(Session["ProjectId"].ToString()); var mappings = GcDynamicTemplateMappings.RetrieveStore(); var rblTemp = new RadioButtonList(); foreach (var template in templates) { if (mappings.Any(mapping => mapping.TemplateId == template.Id.ToString())) { rblTemp.Items.Add(new ListItem($"{template.Name} <a href='/modules/GatherContentImport/ReviewItemsForImport.aspx?" + $"TemplateId={template.Id}&ProjectId={projectId}'> " + $"Review Items for Import </a> <br>{template.Description}", template.Id.ToString()) { Enabled = false }); } else { rblGcTemplates.Items.Add(new ListItem(template.Name + "<br>" + template.Description, template.Id.ToString())); } } foreach (ListItem item in rblTemp.Items) { rblGcTemplates.Items.Add(item); } Session["PostType"] = null; Session["Author"] = null; Session["DefaultStatus"] = null; }
private void PopulateForm() { var credentialsStore = GcDynamicCredentials.RetrieveStore(); if (credentialsStore.IsNullOrEmpty()) { Response.Write("<script>alert('Please setup the GatherContent config first!');window.location='/modules/GatherContentImport/GatherContent.aspx'</script>"); Visible = false; return; } Client = new GcConnectClient(credentialsStore.ToList().First().ApiKey, credentialsStore.ToList().First().Email); var mappings = GcDynamicTemplateMappings.RetrieveStore().FindAll (i => i.AccountId == credentialsStore.ToList().First().AccountId); rptTableMappings.DataSource = mappings; rptTableMappings.DataBind(); }
private void PopulateForm() { var credentialsStore = GcDynamicCredentials.RetrieveStore(); if (credentialsStore.IsNullOrEmpty()) { Response.Write("<script>alert('Please setup your GatherContent config first!');window.location='/modules/GatherContentImport/GatherContent.aspx'</script>"); Visible = false; return; } _client = new GcConnectClient(credentialsStore.ToList().First().ApiKey, credentialsStore.ToList().First().Email); var accountId = Convert.ToInt32(credentialsStore.ToList().First().AccountId); Session["AccountId"] = accountId; accountName.Text = _client.GetAccountById(accountId).Name; var projects = _client.GetProjectsByAccountId(accountId); projects.ToList().ForEach(i => rblGcProjects.Items.Add(new ListItem(i.Name, i.Id.ToString()))); rblGcProjects.SelectedIndex = 0; Session["ProjectId"] = rblGcProjects.SelectedValue; Session["PostType"] = null; Session["Author"] = null; Session["DefaultStatus"] = null; }
private void PopulateForm() { var credentialsStore = GcDynamicCredentials.RetrieveStore(); Session["TemplateId"] = Server.UrlDecode(Request.QueryString["TemplateId"]); Session["ProjectId"] = Server.UrlDecode(Request.QueryString["ProjectId"]); if (credentialsStore.IsNullOrEmpty()) { Response.Write("<script>alert('Please setup your GatherContent config first!');window.location='/modules/GatherContentImport/GatherContent.aspx'</script>"); Visible = false; return; } if (Session["TemplateId"] == null || Session["ProjectId"] == null) { Response.Write("<script>alert('This page is not directly accessible! Review your GatherContent items from Template Mappings page!');window.location='/modules/GatherContentImport/GcEpiTemplateMappings.aspx'</script>"); Visible = false; return; } var currentMapping = GcDynamicTemplateMappings .RetrieveStore().First(i => i.TemplateId == Session["TemplateId"].ToString()); Client = new GcConnectClient(credentialsStore.ToList().First().ApiKey, credentialsStore.ToList().First().Email); var templateId = Convert.ToInt32(Session["TemplateId"]); var gcTemplate = Client.GetTemplateById(templateId); templateName.Text = gcTemplate.Name; var projectId = Convert.ToInt32(Session["ProjectId"]); projectName.Text = Client.GetProjectById(projectId).Name; templateDescription.Text = gcTemplate.Description; var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>(); var recycleBin = contentRepository.GetDescendents(ContentReference.Parse("2")).ToList(); switch (currentMapping.PostType) { case "PageType": ddlDefaultParent.Items.Add(new ListItem("Root Page", "1")); foreach (var cr in contentRepository.GetDescendents(ContentReference.RootPage)) { try { var pageData = contentRepository.Get <PageData>(cr); if (recycleBin.Contains(pageData.ContentLink) || pageData.ContentLink.ID == 2) { continue; } ddlDefaultParent.Items.Add(new ListItem(pageData.PageName, pageData.ContentLink.ID.ToString())); } catch (TypeMismatchException ex) { Console.WriteLine(ex); } } break; case "BlockType": // Add the root parent before everything else. ddlDefaultParent.Items.Add(new ListItem("SysGlobalAssets", "3")); foreach (var cr in contentRepository.GetDescendents(ContentReference.Parse("3"))) { try { var blockData = contentRepository.Get <ContentFolder>(cr); // ReSharper disable once SuspiciousTypeConversion.Global var content = blockData as IContent; // If the block is in recycle bin, // Then do not add it to the drop down. if (recycleBin.Contains(content.ContentLink)) { continue; } // ReSharper disable once PossibleNullReferenceException if (recycleBin.Contains(content.ContentLink) || content.ContentLink.ID == 2) { continue; } ddlDefaultParent.Items.Add(new ListItem(content.Name, content.ContentLink.ID.ToString())); } catch (TypeMismatchException ex) { Console.WriteLine(ex); } } break; } rptGcItems.DataSource = Client.GetItemsByTemplateId(templateId, projectId); rptGcItems.DataBind(); }
protected void BtnImportItem_OnClick(object sender, EventArgs e) { var contentStore = GcDynamicImports.RetrieveStore(); var importCount = 0; foreach (var key in Request.Form) { if (!key.ToString().Contains("chk")) { continue; } var importItem = true; var splitString = key.ToString().Split('$'); var credentialsStore = GcDynamicCredentials.RetrieveStore().ToList().First(); Client = new GcConnectClient(credentialsStore.ApiKey, credentialsStore.Email); var itemId = splitString[2].Substring(3); var item = Client.GetItemById(itemId); var currentMapping = GcDynamicTemplateMappings .RetrieveStore().First(i => i.TemplateId == Session["TemplateId"].ToString()); var parentId = Request.Form[key.ToString().Replace("chk", "ddl")]; var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>(); var contentTypeRepository = ServiceLocator.Current.GetInstance <IContentTypeRepository>(); switch (currentMapping.PostType) { case "PageType": var pageParent = parentId.IsEmpty() ? ContentReference.RootPage : ContentReference.Parse(parentId); var selectedPageType = currentMapping.EpiContentType; var pageTypeList = contentTypeRepository.List().OfType <PageType>(); var pageTypes = pageTypeList as List <PageType> ?? pageTypeList.ToList(); foreach (var pageType in pageTypes) { if (selectedPageType.Substring(5) != pageType.Name) { continue; } PageData myPage; try { myPage = contentRepository.GetDefault <PageData>(pageParent, pageType.ID); } catch (EPiServerException exception) { Console.WriteLine(exception); Response.Write("<script> alert('Invalid Parent Page ID! Try again!') </script>"); break; } foreach (var cs in contentStore) { try { if (cs.ItemId != item.Id) { continue; } var pageData = contentRepository.Get <PageData>(cs.ContentGuid); if (pageData.ParentLink.ID == 2) { GcDynamicImports.DeleteItem(cs.Id); } else { Response.Write("<script> alert('Page Already Exists!') </script>"); importItem = false; importCount = 0; break; } } catch (TypeMismatchException ex) { Console.WriteLine(ex); } } myPage.PageName = item.Name; foreach (var map in currentMapping.EpiFieldMaps) { var splitStrings = map.Split('~'); var fieldName = splitStrings[0]; var propDef = pageType.PropertyDefinitions.ToList().Find(p => p.Name == fieldName); if (propDef == null) { continue; } var configs = item.Config.ToList(); configs.ForEach(j => j.Elements.ForEach(x => { if (x.Name == splitStrings[1]) { myPage.Property[propDef.Name].Value = x.Value; } })); } if (!importItem) { continue; } { var saveActions = Enum.GetValues(typeof(SaveAction)).Cast <SaveAction>().ToList(); saveActions.RemoveAt(1); var gcStatusIdForThisItem = item.CurrentStatus.Data.Id; saveActions.ForEach(x => { if (x.ToString() == currentMapping.StatusMaps.Find(i => i.MappedEpiserverStatus.Split('~')[1] == gcStatusIdForThisItem).MappedEpiserverStatus.Split('~')[0]) { contentRepository.Save(myPage, x, AccessLevel.Administer); var dds = new GcDynamicImports(myPage.ContentGuid, item.Id, DateTime.Now); GcDynamicImports.SaveStore(dds); } else if (currentMapping.StatusMaps.Find(i => i.MappedEpiserverStatus.Split('~')[1] == gcStatusIdForThisItem) .MappedEpiserverStatus.Split('~')[0] == "Use Default Status") { if (x.ToString() != currentMapping.DefaultStatus) { return; } contentRepository.Save(myPage, x, AccessLevel.Administer); var dds = new GcDynamicImports(myPage.ContentGuid, item.Id, DateTime.Now); GcDynamicImports.SaveStore(dds); } }); importCount++; } } break; case "BlockType": var blockParent = parentId.IsEmpty() ? ContentReference.Parse("3") : ContentReference.Parse(parentId); var selectedBlockType = currentMapping.EpiContentType; var blockTypeList = contentTypeRepository.List().OfType <BlockType>(); var blockTypes = blockTypeList as IList <BlockType> ?? blockTypeList.ToList(); foreach (var blockType in blockTypes) { if (selectedBlockType.Substring(6) != blockType.Name) { continue; } BlockData myBlock; try { myBlock = contentRepository.GetDefault <BlockData>(blockParent, blockType.ID); } catch (EPiServerException exception) { Console.WriteLine(exception); Response.Write("<script> alert('Invalid Parent Block ID! Try again!') </script>"); break; } foreach (var cs in contentStore) { try { if (cs.ItemId != item.Id) { continue; } // ReSharper disable once SuspiciousTypeConversion.Global var blockData = contentRepository.Get <BlockData>(cs.ContentGuid) as IContent; // ReSharper disable once PossibleNullReferenceException if (blockData.ParentLink.ID == 2) { GcDynamicImports.DeleteItem(cs.Id); } else { Response.Write("<script> alert('Block Already Exists!') </script>"); importItem = false; break; } } catch (TypeMismatchException ex) { Console.WriteLine(ex); } } // ReSharper disable once SuspiciousTypeConversion.Global var content = myBlock as IContent; // ReSharper disable once PossibleNullReferenceException content.Name = item.Name; foreach (var map in currentMapping.EpiFieldMaps) { var splitStrings = map.Split('~'); var fieldName = splitStrings[0]; var propDef = blockType.PropertyDefinitions.ToList().Find(p => p.Name == fieldName); if (propDef == null) { continue; } var configs = item.Config.ToList(); configs.ForEach(j => j.Elements.ForEach(x => { if (x.Name == splitStrings[1]) { myBlock.Property[propDef.Name].Value = x.Value; } })); } if (!importItem) { continue; } { var saveActions = Enum.GetValues(typeof(SaveAction)).Cast <SaveAction>().ToList(); saveActions.RemoveAt(1); var gcStatusIdForThisItem = item.CurrentStatus.Data.Id; saveActions.ForEach(x => { if (x.ToString() == currentMapping.StatusMaps.Find(i => i.MappedEpiserverStatus.Split('~')[1] == gcStatusIdForThisItem).MappedEpiserverStatus.Split('~')[0]) { contentRepository.Save(content, x, AccessLevel.Administer); var dds = new GcDynamicImports(content.ContentGuid, item.Id, DateTime.Now); GcDynamicImports.SaveStore(dds); } else if (currentMapping.StatusMaps.Find(i => i.MappedEpiserverStatus.Split('~')[1] == gcStatusIdForThisItem) .MappedEpiserverStatus.Split('~')[0] == "Use Default Status") { if (x.ToString() != currentMapping.DefaultStatus) { return; } contentRepository.Save(content, x, AccessLevel.Administer); var dds = new GcDynamicImports(content.ContentGuid, item.Id, DateTime.Now); GcDynamicImports.SaveStore(dds); } }); importCount++; } } break; } } if (importCount == 1) { Response.Write("<script> alert('Item successfully imported!') </script>"); } else if (importCount > 1) { Response.Write($"<script> alert('{importCount} Items successfully imported!') </script>"); } else if (importCount == 0) { Response.Write("<script> alert('No items selected! Please select the checkbox next to the item you would " + "like to import!') </script>"); } PopulateForm(); }
protected void RptGcItems_OnItemCreated(object sender, RepeaterItemEventArgs e) { var gcItem = e.Item.DataItem as GcItem; var queryDefaultParentId = Server.UrlDecode(Request.QueryString["DefaultParentId"]); var enableItemFlag = true; var credentialsStore = GcDynamicCredentials.RetrieveStore().ToList().First(); var contentStore = GcDynamicImports.RetrieveStore(); var contentRepository = ServiceLocator.Current.GetInstance <IContentRepository>(); var parentId = ""; var recycleBin = contentRepository.GetDescendents(ContentReference.Parse("2")).ToList(); Client = new GcConnectClient(credentialsStore.ApiKey, credentialsStore.Email); var currentMapping = GcDynamicTemplateMappings .RetrieveStore().First(i => i.TemplateId == Session["TemplateId"].ToString()); if (gcItem == null) { return; } if (e.Item.FindControl("statusName") is Label statusNameLabel) { statusNameLabel.Text = gcItem.CurrentStatus.Data.Name; } if (e.Item.FindControl("updatedAt") is Label updatedAtLabel) { updatedAtLabel.Text = gcItem.UpdatedAt.Date?.ToShortDateString(); } if (e.Item.FindControl("lnkIsImported") is HyperLink linkIsImported) { linkIsImported.Text = "---------"; if (currentMapping.PostType == "PageType") { _defaultParentId = queryDefaultParentId.IsNullOrEmpty() ? "1" : queryDefaultParentId; foreach (var cs in contentStore) { //Try to create page data of each page in the content store that matches the gcItemId. try { if (cs.ItemId != gcItem.Id) { continue; } var pageData = contentRepository.Get <PageData>(cs.ContentGuid); //Setting the parentId and making sure the drop down loads from Root Page. parentId = pageData.ParentLink.ID.ToString(); enableItemFlag = false; _defaultParentId = "1"; //if page is in trash, then set the import status to 'Page in Trash'. if (recycleBin.Contains(pageData.ContentLink)) { linkIsImported.Text = "Page in Trash"; parentId = "2"; break; } linkIsImported.Text = "Page Imported"; linkIsImported.NavigateUrl = pageData.LinkURL; break; } catch (Exception ex) { Console.WriteLine(ex); //This is in case the user moved the page to trash and deleted it permanently. if (ex is TypeMismatchException) { continue; } GcDynamicImports.DeleteItem(cs.Id); } } } else { _defaultParentId = queryDefaultParentId.IsNullOrEmpty() ? "3" : queryDefaultParentId; foreach (var cs in contentStore) { try { if (cs.ItemId != gcItem.Id) { continue; } // ReSharper disable once SuspiciousTypeConversion.Global var blockData = contentRepository.Get <BlockData>(cs.ContentGuid) as IContent; // ReSharper disable once PossibleNullReferenceException //Setting the parentId and making sure the drop down loads from Root Folder. parentId = blockData.ParentLink.ID.ToString(); enableItemFlag = false; _defaultParentId = "3"; //if the block is in trash, then set the import status to 'Block in Trash'. if (recycleBin.Contains(blockData.ContentLink)) { linkIsImported.Text = "Block in Trash"; parentId = "2"; break; } linkIsImported.Text = "Block Imported"; break; } catch (Exception ex) { Console.WriteLine(ex); //This is in case the user moved the block to trash and deleted it permanently. if (ex is TypeMismatchException) { continue; } GcDynamicImports.DeleteItem(cs.Id); } } } } if (e.Item.FindControl("ddlParentId") is DropDownList dropDownListParentId) { dropDownListParentId.ID = $"ddl{gcItem.Id}"; if (currentMapping.PostType == "PageType") { var parentData = contentRepository.Get <PageData>(ContentReference.Parse(_defaultParentId)); dropDownListParentId.Items.Add(new ListItem(parentData.PageName, parentData.ContentLink.ID.ToString())); foreach (var cr in contentRepository.GetDescendents(ContentReference.Parse(_defaultParentId))) { try { var pageData = contentRepository.Get <PageData>(cr); if (recycleBin.Contains(pageData.ContentLink) || pageData.ContentLink.ID == 2) { //if the page is in trash, then add recycle bin to the drop down. if (parentId == "2") { dropDownListParentId.Items.Add(new ListItem( contentRepository.Get <PageData>(ContentReference.WasteBasket).Name, "2")); } } else { dropDownListParentId.Items.Add(new ListItem(pageData.PageName, pageData.ContentLink.ID.ToString())); } } catch (TypeMismatchException ex) { Console.WriteLine(ex); } } } else { // ReSharper disable once SuspiciousTypeConversion.Global var parentData = contentRepository.Get <ContentFolder>(ContentReference.Parse(_defaultParentId)); // ReSharper disable once PossibleNullReferenceException dropDownListParentId.Items.Add(new ListItem(parentData.Name, parentData.ContentLink.ID.ToString())); foreach (var cr in contentRepository.GetDescendents(ContentReference.Parse(_defaultParentId))) { try { // ReSharper disable once SuspiciousTypeConversion.Global var contentFolder = contentRepository.Get <ContentFolder>(cr); // ReSharper disable once PossibleNullReferenceException if (parentId == "2") { dropDownListParentId.Items.Add(new ListItem( contentRepository.Get <PageData>(ContentReference.WasteBasket).Name, "2")); } dropDownListParentId.Items.Add(new ListItem(contentFolder.Name, contentFolder.ContentLink.ID.ToString())); } catch (TypeMismatchException ex) { Console.WriteLine(ex); } } } if (enableItemFlag) { dropDownListParentId.Enabled = true; } else { dropDownListParentId.SelectedValue = parentId; } } if (e.Item.FindControl("chkItem") is CheckBox checkBoxItem) { checkBoxItem.ID = $"chk{gcItem.Id}"; if (enableItemFlag) { checkBoxItem.Enabled = true; checkBoxItem.Visible = true; btnImportItem.Enabled = true; } } if (!(e.Item.FindControl("lnkItemName") is HyperLink linkItemName)) { return; } linkItemName.Text = gcItem.Name; linkItemName.NavigateUrl = $"https://{Client.GetAccountById(Convert.ToInt32(credentialsStore.AccountId)).Slug}" + $".gathercontent.com/item/{gcItem.Id}"; }
private void PopulateForm() { var credentialsStore = GcDynamicCredentials.RetrieveStore(); if (credentialsStore.IsNullOrEmpty()) { Response.Write("<script>alert('Please setup your GatherContent config first!');window.location='/modules/GatherContentImport/GatherContent.aspx'</script>"); Visible = false; return; } if (Session["ProjectId"] == null || Session["TemplateId"] == null || Session["PostType"] == null || (string)Session["PostType"] == "-1") { Response.Write("<script>alert('Please set the Mapping Defaults!');window.location='/modules/GatherContentImport/NewGcMappingStep3.aspx'</script>"); Visible = false; return; } _client = new GcConnectClient(credentialsStore.ToList().First().ApiKey, credentialsStore.ToList().First().Email); var projectId = Convert.ToInt32(Session["ProjectId"]); var templateId = Convert.ToInt32(Session["TemplateId"]); projectName.Text = _client.GetProjectById(projectId).Name; templateName.Text = _client.GetTemplateById(templateId).Name; templateDescription.Text = _client.GetTemplateById(templateId).Description; var tHeadRow = new TableRow { Height = 42 }; tHeadRow.Cells.Add(new TableCell { Text = "GatherContent Field" }); tHeadRow.Cells.Add(new TableCell { Text = "Mapped EPiServer Field" }); tableMappings.Rows.Add(tHeadRow); var gcFields = _client.GetTemplateById(templateId).Config.ToList(); foreach (var field in gcFields) { foreach (var element in field.Elements) { var tRow = new TableRow(); tableMappings.Rows.Add(tRow); for (var cellIndex = 1; cellIndex <= 2; cellIndex++) { var tCell = new TableCell { Width = 500 }; if (cellIndex is 1) { tCell.Text = $"<span style='font-weight: Bold;'>{element.Label}</span><br>Type: {element.Type}<br>Limit: " + $"{element.Limit}<br>Description: {element.MicroCopy}<br>"; } else { var contentTypeRepository = ServiceLocator.Current.GetInstance <IContentTypeRepository>(); //if (Session["EpiContentType"].ToString() is "MediaType") //{ // var ddlMetaData = new DropDownList {Height = 28, Width = 194}; // ddlMetaData.Items.Add(new ListItem("Media Content", "MediaContent")); // tCell.Controls.Add(ddlMetaData); //} //else //{ if (Session["EpiContentType"].ToString().StartsWith("block-")) { var contentTypeList = contentTypeRepository.List().OfType <BlockType>(); var myProperty = new BlockType(); var blockTypes = contentTypeList as IList <BlockType> ?? contentTypeList.ToList(); foreach (var i in blockTypes) { if (Session["EpiContentType"].ToString().Substring(6) != i.Name) { continue; } myProperty = i; break; } var ddlMetaData = new DropDownList { Height = 28, Width = 194 }; ddlMetaData.Items.Add(new ListItem("Do Not Import", "-1")); myProperty.PropertyDefinitions.ToList().ForEach(i => ddlMetaData.Items.Add(new ListItem(i.Name, i.Name))); ddlMetaData.ID = "meta-" + element.Name; tCell.Controls.Add(ddlMetaData); } else if (Session["EpiContentType"].ToString().StartsWith("page-")) { var contentTypeList = contentTypeRepository.List().OfType <PageType>(); var myProperty = new PageType(); var pageTypes = contentTypeList as IList <PageType> ?? contentTypeList.ToList(); foreach (var i in pageTypes) { if (Session["EpiContentType"].ToString().Substring(5) != i.Name) { continue; } myProperty = i; break; } var ddlMetaData = new DropDownList { Height = 28, Width = 194 }; ddlMetaData.Items.Add(new ListItem("Do Not Import", "-1")); myProperty.PropertyDefinitions.ToList().ForEach(i => ddlMetaData.Items.Add(new ListItem(i.Name, i.Name))); ddlMetaData.ID = "meta-" + element.Name; tCell.Controls.Add(ddlMetaData); } //} } tRow.Cells.Add(tCell); } } } }
private void PopulateForm() { var credentialsStore = GcDynamicCredentials.RetrieveStore(); if (credentialsStore.IsNullOrEmpty()) { Response.Write("<script>alert('Please setup your GatherContent config first!');window.location='/modules/GatherContentImport/GatherContent.aspx'</script>"); Visible = false; return; } if (Session["ProjectId"] == null || Session["TemplateId"] == null) { Response.Write("<script>alert('Please select the GatherContent Template!');window.location='/modules/GatherContentImport/NewGcMappingStep2.aspx'</script>"); Visible = false; return; } EnableDdl(); _client = new GcConnectClient(credentialsStore.ToList().First().ApiKey, credentialsStore.ToList().First().Email); var projectId = Convert.ToInt32(Session["ProjectId"]); var templateId = Convert.ToInt32(Session["TemplateId"]); projectName.Text = _client.GetProjectById(projectId).Name; templateName.Text = _client.GetTemplateById(templateId).Name; templateDescription.Text = _client.GetTemplateById(templateId).Description; var userProvider = ServiceLocator.Current.GetInstance <UIUserProvider>(); var epiUsers = userProvider.GetAllUsers(0, 200, totalRecords: out int _); epiUsers.ToList().ForEach(epiUser => ddlAuthors.Items.Add(new ListItem(epiUser.Username, epiUser.Username))); var saveActions = Enum.GetValues(typeof(SaveAction)).Cast <SaveAction>().ToList(); saveActions.ToList().ForEach(i => ddlStatuses.Items.Add(new ListItem(i.ToString(), i.ToString()))); if (Session["PostType"] == null || Session["Author"] == null || Session["DefaultStatus"] == null) { ddlPostTypes.SelectedIndex = 0; ddlAuthors.SelectedIndex = 0; ddlStatuses.SelectedIndex = 0; Session["PostType"] = ddlPostTypes.SelectedValue; Session["Author"] = ddlAuthors.SelectedValue; Session["DefaultStatus"] = ddlStatuses.SelectedValue; } else { ddlPostTypes.Items.Remove(ddlPostTypes.Items.FindByValue("-1")); ddlPostTypes.SelectedValue = Session["PostType"].ToString(); ddlAuthors.SelectedValue = Session["Author"].ToString(); ddlStatuses.SelectedValue = Session["DefaultStatus"].ToString(); var contentTypeRepository = ServiceLocator.Current.GetInstance <IContentTypeRepository>(); if (Session["PostType"].ToString() is "PageType") { var contentTypeList = contentTypeRepository.List().OfType <PageType>(); var pageTypes = contentTypeList as IList <PageType> ?? contentTypeList.ToList(); pageTypes.ForEach(i => { if (i.ID != 1 && i.ID != 2) { ddlEpiContentTypes.Items.Add(new ListItem(i.Name, "page-" + i.Name)); } }); ddlEpiContentTypes.Enabled = true; btnNextStep.Enabled = true; } else if (Session["PostType"].ToString() is "BlockType") { var contentTypeList = contentTypeRepository.List().OfType <BlockType>(); var blockTypes = contentTypeList as IList <BlockType> ?? contentTypeList.ToList(); blockTypes.ToList().ForEach(i => ddlEpiContentTypes.Items.Add(new ListItem(i.Name, "block-" + i.Name))); ddlEpiContentTypes.Enabled = true; btnNextStep.Enabled = true; } //else if (Session["PostType"].ToString() is "MediaType") //{ // ddlEpiContentTypes.Items.Add(new ListItem("Media Data", "MediaType")); // ddlEpiContentTypes.Enabled = true; // btnNextStep.Enabled = true; //} if (Session["EpiContentType"] != null) { ddlEpiContentTypes.SelectedValue = Session["EpiContentType"].ToString(); } } var gcStatuses = _client.GetStatusesByProjectId(projectId); var tHeadRow = new TableRow { Height = 42 }; tHeadRow.Cells.Add(new TableCell { Text = "GatherContent Status" }); tHeadRow.Cells.Add(new TableCell { Text = "Mapped EPiServer Status" }); //tHeadRow.Cells.Add(new TableCell { Text = "On Import, Change GatherContent Status" }); tableGcStatusesMap.Rows.Add(tHeadRow); foreach (var status in gcStatuses) { var tRow = new TableRow(); tableGcStatusesMap.Rows.Add(tRow); for (var cellIndex = 1; cellIndex <= 2; cellIndex++)//Need it to make the highest index 3 in the next version. { var tCell = new TableCell(); if (cellIndex is 3) { var ddlOnImportGcStatuses = new DropDownList { Height = 28, Width = 194 }; ddlOnImportGcStatuses.Items.Add(new ListItem("Do Not Change", "1")); gcStatuses.ToList().ForEach(i => ddlOnImportGcStatuses.Items.Add(new ListItem(i.Name, i.Id))); ddlOnImportGcStatuses.ID = "onImportGc-" + status.Id; tCell.Controls.Add(ddlOnImportGcStatuses); } else if (cellIndex is 2) { var ddlEpiStatuses = new DropDownList { Height = 28, Width = 194 }; ddlEpiStatuses.Items.Add(new ListItem("Use Default Status", "Use Default Status")); saveActions.ToList().ForEach(i => ddlEpiStatuses.Items.Add(new ListItem(i.ToString(), i.ToString()))); ddlEpiStatuses.ID = "mappedEPi-" + status.Id; tCell.Controls.Add(ddlEpiStatuses); } else if (cellIndex is 1) { tCell.Text = status.Name; } tRow.Cells.Add(tCell); } } }