/// <summary> /// General method to make an HRI API call /// </summary> /// <param name="values"></param> /// <returns></returns> private JObject MakeApiCall(Dictionary <string, string> values) { // Get ahold of the root/home node IPublishedContent root = Umbraco.ContentAtRoot().First(); // Get the API uri string apiUri = root.GetProperty("apiUri").Value.ToString(); // Apend the command to determine user availability var valuesList = values.Select(_ => String.Format("{0}={1}", HttpUtility.UrlEncode(_.Key), HttpUtility.UrlEncode(_.Value))); string userNameCheckApiString = apiUri + "/Registration?" + String.Join("&", valuesList); // Create a web client to access the API // Create a JSON object to hold the response JObject json; using (var client = new WebClient()) { // Set the format to JSON client.Headers[HttpRequestHeader.ContentType] = "application/json"; // Execute a GET and convert the response to a JSON object json = JObject.Parse(client.DownloadString(userNameCheckApiString)); } // Return whether or not it is available return(json); }
/// <summary> /// Crawl Site Pages /// </summary> /// <returns>Dictionary of Results</returns> private Dictionary <string, string> CrawlSitePages() { IPublishedContent homeNode = Umbraco.ContentAtRoot().FirstOrDefault(); var crawlResults = new Dictionary <string, string>(); if (homeNode != null) { _siteUrls = new List <string>(); _siteUrls.Add($"{App.Settings.TLD}{homeNode.Url}"); GetNextNodeUrl(homeNode); using (var httpClient = new HttpClient()) { foreach (string siteUrl in _siteUrls) { HttpResponseMessage response = null; try { response = httpClient.GetAsync(siteUrl).Result; crawlResults.Add(siteUrl, response.StatusCode.ToString()); } catch (Exception ex) { crawlResults.Add(siteUrl, $"Error: {response.StatusCode.ToString()} | Exception: {ex.Message}"); } } } } return(crawlResults); }
public QueryResultModel PostTemplateQuery(QueryModel model) { var queryExpression = new StringBuilder(); IEnumerable <IPublishedContent> contents; if (model == null) { contents = Umbraco.ContentAtRoot().FirstOrDefault().Children(); queryExpression.Append("Umbraco.ContentAtRoot().FirstOrDefault().Children()"); } else { contents = PostTemplateValue(model, queryExpression); } // timing should be fairly correct, due to the fact that all the linq statements are yield returned. var timer = new Stopwatch(); timer.Start(); var results = contents.ToList(); timer.Stop(); return(new QueryResultModel { QueryExpression = queryExpression.ToString(), ResultCount = results.Count, ExecutionTime = timer.ElapsedMilliseconds, SampleResults = results.Take(20).Select(x => new TemplateQueryResult { Icon = "icon-document", Name = x.Name }) }); }
private void SendContactFormReceivedEmail(ContactFormViewModel vm) { var siteSettings = Umbraco.ContentAtRoot().DescendantsOrSelfOfType("siteSettings").FirstOrDefault(); if (siteSettings == null) { throw new Exception("There are no site settings"); } var fromAddress = siteSettings.Value <string>("emailFromAddress"); if (string.IsNullOrEmpty(fromAddress)) { throw new Exception("Missing from address for email in site settings"); } var toAddresses = siteSettings.Value <string>("emailAdminAccounts").Trim(); if (string.IsNullOrEmpty(toAddresses)) { throw new Exception("Missing to addresses for email in site settings"); } var smtpMessage = CreateSmtpMessage(fromAddress, toAddresses, vm); //smtp client is picking up configuration from webConfig; using (var smtp = new SmtpClient()) { smtp.Send(smtpMessage); } }
protected void SendEmail(string email, string title, string content, string fromEmail = null) { // Get ahold of the root/home node IPublishedContent root = Umbraco.ContentAtRoot().First(); // Get the SMTP server string smtpServer = root.GetProperty("smtpServer").Value.ToString(); // Get the SMTP port int smtpPort = Convert.ToInt32(root.GetProperty("smtpPort").Value); // Get the SMTP User Name string exchangeAccountUserName = root.GetProperty("exchangeAccountUserName").Value.ToString(); // Get the SMTP Password string exchangeAccountPassword = root.GetProperty("exchangeAccountPassword").Value.ToString(); // Get the SMTP email account string smtpEmail = fromEmail != null ? fromEmail : root.GetProperty("smtpEmailAddress").Value.ToString(); // Create a message MailMessage message = new MailMessage(smtpEmail, email, title, content); // Create an SMTP client object and send the message with it SmtpClient smtp = new SmtpClient(smtpServer, smtpPort); smtp.Credentials = new NetworkCredential(exchangeAccountUserName, exchangeAccountPassword); // Try to send the message smtp.Send(message); }
public IHttpActionResult Token([FromBody] string secret) { if (secret.IsNullOrWhiteSpace()) { return(BadRequest("secret parameter must be specified")); } var clientIp = GetClientIp(); if (clientIp == null) { return(BadRequest("Can't detect clientIp")); } if (_tokenRequestFails.Value.Count(r => r.Ip == clientIp && r.DateTime >= DateTime.Now.AddHours(-3)) > 3) { return(BadRequest("To many failed attempts")); } var discordBotFolder = Umbraco.ContentAtRoot() .FirstOrDefault(n => n.IsDocumentType(DiscordBotFolder.ModelTypeAlias)) as DiscordBotFolder; if (discordBotFolder?.Secret.IsNullOrWhiteSpace() != false) { return(BadRequest("Invalid server configuration")); } if (secret != discordBotFolder.Secret) { _tokenRequestFails.Value.Add(new TokenRequestFail(DateTime.Now, clientIp)); return(BadRequest("Invalid secret")); } return(Ok(_token.Value)); }
public IHttpActionResult BingoConfiguration(string token, int wordCount) { if (token != _token.Value) { return(Unauthorized()); } //todo this should be moved into a service var discordBotFolder = Umbraco.ContentAtRoot() .FirstOrDefault(n => n.IsDocumentType(DiscordBotFolder.ModelTypeAlias)) as DiscordBotFolder; var bingoFolder = discordBotFolder.FirstChild <BingoFolder>(); var configuration = new BingoConfiguration(); configuration.Words = bingoFolder.FirstChild <BingoWordsFolder>() .Children <BingoWord>().Select(w => w.Name).ToList(); configuration.KeyedPhrases = bingoFolder.FirstChild <BingoPhrasesFolder>().Children <BingoPhrase>() .Select(kp => new KeyedPhrases { Key = kp.Key, Phrases = kp.Collection.Select(p => new Phrase { Boost = p.Boost, Text = p.Text }).ToList() }) .ToList(); var autoRoundSettings = bingoFolder.FirstChild <BingoSettings>().FirstChild <Models.Published.AutoRoundSettings>(); configuration.AutoRoundSettings = new Models.Api.DiscordBot.AutoRoundSettings { MaximumTimeout = autoRoundSettings.MaximumTimeout, MinimumTimeout = autoRoundSettings.MinimumTimeOut, PreferedTimeout = autoRoundSettings.PreferedTimeout, PreferedTimeoutSkewPercentage = autoRoundSettings.PreferedTimeoutSkewPercentage }; return(Ok(configuration)); }
public ActionResult RenderMainNavigation() { var root = Umbraco.ContentAtRoot().First(); var navigation = new Navigation(root); return(PartialView("Layout/_Navigation", navigation.GetItems(false))); }
/// <summary> /// The AddDiscounts. /// </summary> private void AddDiscounts() { //Get Discount Setting From Umbraco Model var home = Umbraco.ContentAtRoot().FirstOrDefault(); var setting = home.Descendants <Setting>("Setting").FirstOrDefault(); List <Umbraco.Web.PublishedModels.DiscountSetting> tempDiscountSettings = setting.DiscountSetting.ToList(); Cart cart = CartSession; foreach (Umbraco.Web.PublishedModels.DiscountSetting item in tempDiscountSettings) { cart.DiscountSettings.Add(new DiscountSetting() { //Add Settings DiscountAmount = decimal.Parse(item.DiscountAmount), DiscountName = item.DiscountName, MinOrder = decimal.Parse(item.MinOrder), DiscountCode = item.DiscountCode, OrderType = Utility.GetEnumValueFromDescription <Enums.DiscountorderType>(item.OrderType), StartingDate = item.StartingDate, ExpirationDate = item.ExpirationDate }); } CartSession = cart; }
public bool CreateTestNodes(int quantity) { var root = Umbraco.ContentAtRoot().First(); CreateTestNodesUnderParent(quantity, root.Id); return(true); }
public bool CreateNestedTestNodes(int quantityPerLevel, int numberOfLevels = 1) { var root = Umbraco.ContentAtRoot().First(); CreateTestNodeForEachParentLimitByLevel(quantityPerLevel, numberOfLevels, 1, new List <int> { root.Id }); return(true); }
public ActionResult HandleContactForm(ContactFormViewModel vm) { if (!ModelState.IsValid) { ModelState.AddModelError("Error", "Please check the form."); return(CurrentUmbracoPage()); } var siteSettings = Umbraco.ContentAtRoot().DescendantsOrSelfOfType("siteSettings").FirstOrDefault(); if (siteSettings != null) { var secretKey = siteSettings.Value <string>("recaptchaSecretKey"); //We might not have configure captcha so check if (!string.IsNullOrEmpty(secretKey) && !string.IsNullOrEmpty(Request.Form["GoogleCaptchaToken"])) { var isCaptchaValid = IsCaptchaValid(Request.Form["GoogleCaptchaToken"], secretKey); if (!isCaptchaValid) { ModelState.AddModelError("Captcha", "The captcha is not valid are you human?"); return(CurrentUmbracoPage()); } } } try { //Create a new contact form in umbraco //Get a handle to "Contact Forms" var contactForms = Umbraco.ContentAtRoot().DescendantsOrSelfOfType("contactForms").FirstOrDefault(); if (contactForms != null) { var newContact = Services.ContentService.Create("Contact", contactForms.Id, "contactForm"); newContact.SetValue("contactName", vm.Name); newContact.SetValue("contactEmail", vm.Email); newContact.SetValue("contactSubject", vm.Subject); newContact.SetValue("contactComments", vm.Comments); Services.ContentService.SaveAndPublish(newContact); } //Send out an email to site admin //SendContactFormReceivedEmail(vm); _emailService.SendContactNotificationToAdmin(vm); //Return confirmation message to user TempData["status"] = "OK"; return(RedirectToCurrentUmbracoPage()); } catch (Exception exc) { Logger.Error <ContactController>("There was an error in the contact form submission", exc.Message); ModelState.AddModelError("Error", "Sorry there was a problem noting your details. Would you please try again later?"); } return(CurrentUmbracoPage()); }
private IEnumerable <IPublishedContent> GetAllPublishedContent() { // Get all published content var allPublishedContent = new List <IPublishedContent>(); foreach (var publishedContentRoot in Umbraco.ContentAtRoot()) { allPublishedContent.AddRange(publishedContentRoot.DescendantsOrSelf()); } return(allPublishedContent); }
public IEnumerable <KeyValuePair <int, string> > GetAllContentPages() { var pages = new List <KeyValuePair <int, string> >(); var home = _contentService.GetRootContent().FirstOrDefault(); pages.Add(new KeyValuePair <int, string>(home.Id, home.Name)); var allFolders = Umbraco.ContentAtRoot().FirstOrDefault().Children <IPublishedContent>().Where(x => x.IsVisible()); pages.AddRange(allFolders.Select(x => new KeyValuePair <int, string>(x.Id, x.Name))); return(pages); }
public List <LinkedNodesDataModel> GetLinkedNodes(string currentUdi, bool isContent) { List <LinkedNodesDataModel> relatedLinks = new List <LinkedNodesDataModel>(); // Get all root nodes foreach (var root in Umbraco.ContentAtRoot()) { relatedLinks = GetRelatedProperty(relatedLinks, root, currentUdi, isContent); GetChildren(relatedLinks, root, currentUdi, isContent); } return(relatedLinks); }
public List <string> GetAndTransformPublicContentPriceFilter() { IPublishedContent priceFilter = Umbraco.ContentAtRoot().FirstOrDefault(x => x.ContentType.Alias == "home").FirstChildOfType("shop").FirstChildOfType("filtersFolder").Descendants().Where(x => x.ContentType.Alias == "filterType" && x.IsPublished() && x.Name == "Price").FirstOrDefault(); List <string> myList = new List <string>(); foreach (var child in priceFilter.Children) { myList.Add(child.Value("queryValue").ToString()); } return(myList); }
public ActionResult RenderContactForm() { var vm = new ContactFormViewModel(); var siteSettings = Umbraco.ContentAtRoot().DescendantsOrSelfOfType("siteSettings").FirstOrDefault(); if (siteSettings != null) { var siteKey = siteSettings.Value <string>("recaptchaSiteKey"); vm.RecaptchaSiteKey = siteKey; } return(PartialView("~/Views/Partials/Contact Form.cshtml", vm)); }
/// <summary> /// This will send out an email to site admins saying a contact form has been submitted /// </summary> /// <param name="vm"></param> private void SendContactFormReceivedEmail(ContactFormViewModel vm) { //Read email FROM and TO addresses //Get site settings var siteSettings = Umbraco.ContentAtRoot().DescendantsOrSelfOfType("siteSettings").FirstOrDefault(); if (siteSettings == null) { throw new Exception("There are no site settings"); } var fromAddress = siteSettings.Value <string>("emailSettingsFromAddress"); var toAddresses = siteSettings.Value <string>("emailSettingsAdminAccounts"); if (string.IsNullOrEmpty(fromAddress)) { throw new Exception("There needs to be a from address in site settings"); } if (string.IsNullOrEmpty(toAddresses)) { throw new Exception("There needs to be a to address in site settings"); } //Construct the actual email var emailSubject = "There has been a contact form submitted"; var emailBody = $"A new contact form has been received from {vm.Name}. Their comments were: {vm.Comments}"; var smtpMessage = new MailMessage(); smtpMessage.Subject = emailSubject; smtpMessage.Body = emailBody; smtpMessage.From = new MailAddress(fromAddress); var toList = toAddresses.Split(','); foreach (var item in toList) { if (!string.IsNullOrEmpty(item)) { smtpMessage.To.Add(item); } } //Send via whatever email service using (var smtp = new SmtpClient()) { smtp.Send(smtpMessage); } }
public SkriftViewPage() { Settings = AppCaches.RequestCache.GetCacheItem("globalSettings", () => { // should move this to a function somewhere... var content = Umbraco.ContentAtRoot().FirstOrDefault(x => x.ContentType.Alias == GlobalSettings.ModelTypeAlias); if (content is GlobalSettings settings) { return(settings); } return(null); }); }
public List <UmbracoApprenticeshipModel> GetUmbracoApprenticeships() { List <UmbracoApprenticeshipModel> model = new List <UmbracoApprenticeshipModel>(); loggedMember = GetLoggedMember(); IPublishedContent homePage = Umbraco.ContentAtRoot().Where(f => f.IsDocumentType(HOMEPAGE_DOCTYPE_ALIAS)).FirstOrDefault(); IPublishedContent apprenticeshipList = homePage.Descendants().Where(x => x.IsDocumentType(APPR_LIST_DOCTYPE_ALIAS)).FirstOrDefault(); foreach (IPublishedContent item in apprenticeshipList.Children.OrderBy(x => x.Name)) { // switch case here for member type int memberId = GetEmployerTypeId(item, loggedMember.MemberType); if (memberId == loggedMember.MemberId) { int apprenticeshipId = item.Id; string apprenticeshipName = item.Name; DateTime postDate = (DateTime)item.GetProperty("postDate").GetValue(); DateTime startDate = (DateTime)item.GetProperty("startDate").GetValue(); DateTime endDate = (DateTime)item.GetProperty("endDate").GetValue(); string title = item.GetProperty("title").GetValue().ToString(); string country = item.GetProperty("country").GetValue().ToString(); string metaName = item.GetProperty("metaName").GetValue().ToString(); string metaDescription = item.GetProperty("metaDescription").GetValue().ToString(); string[] metaKeywords = (string[])item.GetProperty("metaKeywords").GetValue(); string[] categories = (string[])item.GetProperty("category").GetValue(); string jobSector = item.GetProperty("jobSector").GetValue().ToString(); model.Add(new UmbracoApprenticeshipModel() { ApprenticeshipId = apprenticeshipId, ApprenticeshipName = apprenticeshipName, PostDate = postDate, StartDate = startDate, EndDate = endDate, Title = title, Country = country, MemberId = memberId, MetaName = metaName, MetaDescription = metaDescription, MetaKeywords = utilities.ConcatenateStringArray(metaKeywords), JobSector = jobSector, SelectedCategories = categories }); } } return(model); }
public IHttpActionResult CreateSupplier(SupplierDTO supplier) { var rootNode = Umbraco.ContentAtRoot().OfType <RegisteredPeople>().FirstOrDefault(); var content = Services.ContentService.Create(supplier.PersonName, rootNode.Id, Supplier.ModelTypeAlias); content.SetValue(Supplier.GetModelPropertyType(x => x.PersonName).Alias, supplier.PersonName); content.SetValue(Supplier.GetModelPropertyType(x => x.Phone).Alias, supplier.Phone); content.SetValue(Supplier.GetModelPropertyType(x => x.Email).Alias, supplier.Email); content.SetValue(Supplier.GetModelPropertyType(x => x.Description).Alias, supplier.Description); content.SetValue(Supplier.GetModelPropertyType(x => x.Type).Alias, "Supplier"); var result = Services.ContentService.Save(content); return(HandleContentSave(result)); }
public List <UmbracoArticleModel> GetUmbracoArticles() { List <UmbracoArticleModel> model = new List <UmbracoArticleModel>(); loggedMember = GetLoggedMember(); IPublishedContent homePage = Umbraco.ContentAtRoot().Where(f => f.IsDocumentType(HOMEPAGE_DOCTYPE_ALIAS)).FirstOrDefault(); IPublishedContent articlesList = homePage.Descendants().Where(x => x.IsDocumentType(ARTICLELIST_DOCTYPE_ALIAS)).FirstOrDefault(); foreach (IPublishedContent item in articlesList.Children.OrderBy(x => x.Name)) { // switch case here for member type int memberId = GetMemberTypeId(item, loggedMember.MemberType); if (memberId == loggedMember.MemberId) { int articleId = item.Id; string name = item.Name; DateTime articleDate = (DateTime)item.GetProperty("articleDate").GetValue(); string authorName = item.GetProperty("authorName").GetValue().ToString(); string title = item.GetProperty("title").GetValue().ToString(); var description = item.GetProperty("description").GetValue(); string country = item.GetProperty("country").GetValue().ToString(); string metaName = item.GetProperty("metaName").GetValue().ToString(); string metaDescription = item.GetProperty("metaDescription").GetValue().ToString(); string[] metaKeywords = (string[])item.GetProperty("metaKeywords").GetValue(); string[] categories = (string[])item.GetProperty("category").GetValue(); model.Add(new UmbracoArticleModel() { ArticleId = articleId, ArticleName = name, ArticleDate = articleDate, AuthorName = authorName, Title = title, Description = (HtmlString)description, Country = country, MemberId = memberId, MetaName = metaName, MetaDescription = metaDescription, MetaKeywords = utilities.ConcatenateStringArray(metaKeywords), SelectedCategories = categories }); } } return(model); }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.Username, model.Password)) { FormsAuthentication.SetAuthCookie(model.Username, true); var rootPrivate = Umbraco.ContentAtRoot().First(x => x.Name == "Private"); return(Redirect(rootPrivate.Url)); } else { return(Redirect("http://localhost:52587/Login")); } } return(PartialView(model)); }
public IHttpActionResult CreateVolunteer(VolunteerDTO volunteer) { var rootNode = Umbraco.ContentAtRoot().OfType <RegisteredPeople>().FirstOrDefault(); var content = Services.ContentService.Create(volunteer.PersonName, rootNode.Id, Volunteer.ModelTypeAlias); content.SetValue(Volunteer.GetModelPropertyType(x => x.PersonName).Alias, volunteer.PersonName); content.SetValue(Volunteer.GetModelPropertyType(x => x.Phone).Alias, volunteer.Phone); content.SetValue(Volunteer.GetModelPropertyType(x => x.Age).Alias, volunteer.Age); content.SetValue(Volunteer.GetModelPropertyType(x => x.HomeAddress).Alias, volunteer.HomeAddress); content.SetValue(Volunteer.GetModelPropertyType(x => x.Description).Alias, volunteer.Description); content.SetValue(Volunteer.GetModelPropertyType(x => x.Type).Alias, "Volunteer"); var result = Services.ContentService.Save(content); return(HandleContentSave(result)); }
public IHttpActionResult CreateExtraDoctor(ExtraDoctorDTO extraDoctor) { var rootNode = Umbraco.ContentAtRoot().OfType <RegisteredPeople>().FirstOrDefault(); var content = Services.ContentService.Create(extraDoctor.PersonName, rootNode.Id, ExtraDoctor.ModelTypeAlias); content.SetValue(ExtraDoctor.GetModelPropertyType(x => x.PersonName).Alias, extraDoctor.PersonName); content.SetValue(ExtraDoctor.GetModelPropertyType(x => x.Phone).Alias, extraDoctor.Phone); content.SetValue(ExtraDoctor.GetModelPropertyType(x => x.Age).Alias, extraDoctor.Age); content.SetValue(ExtraDoctor.GetModelPropertyType(x => x.Address).Alias, extraDoctor.HomeAddress); content.SetValue(ExtraDoctor.GetModelPropertyType(x => x.MedicalSpecialization).Alias, extraDoctor.Description); content.SetValue(ExtraDoctor.GetModelPropertyType(x => x.Type).Alias, "ExtraDoctor"); var result = Services.ContentService.Save(content); return(HandleContentSave(result)); }
public ActionResult Apprenticeship_Create([DataSourceRequest] DataSourceRequest request, UmbracoApprenticeshipModel model) { IPublishedContent homePage = Umbraco.ContentAtRoot().Where(f => f.IsDocumentType(HOMEPAGE_DOCTYPE_ALIAS)).FirstOrDefault(); IPublishedContent apprenticeshipList = homePage.Descendants().Where(x => x.IsDocumentType(APPR_LIST_DOCTYPE_ALIAS)).FirstOrDefault(); var parentId = apprenticeshipList.Id; var contentService = Services.ContentService; if (model != null && ModelState.IsValid) { var content = contentService.Create(model.ApprenticeshipName, parentId, Apprenticeship.ModelTypeAlias); UpdateApprenticeshipGridFields(content, model); contentService.SaveAndPublish(content); model.ApprenticeshipId = content.Id; } return(Json(new[] { model }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet)); }
public ActionResult UmbracoArticle_Create([DataSourceRequest] DataSourceRequest request, UmbracoArticleModel model) { IPublishedContent homePage = Umbraco.ContentAtRoot().Where(f => f.IsDocumentType(HOMEPAGE_DOCTYPE_ALIAS)).FirstOrDefault(); IPublishedContent articlesList = homePage.Descendants().Where(x => x.IsDocumentType(ARTICLELIST_DOCTYPE_ALIAS)).FirstOrDefault(); var parentId = articlesList.Id; var contentService = Services.ContentService; if (model != null && ModelState.IsValid) { var article = contentService.Create(model.ArticleName, parentId, Article.ModelTypeAlias); UpdateArticleGridFields(article, model); contentService.SaveAndPublish(article); model.ArticleId = article.Id; } return(Json(new[] { model }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet)); }
/// <summary> /// initialise the controller /// </summary> public PageContentController( IProductsService productsService) { //get the global site settings page to use var homePage = Umbraco.ContentAtRoot().FirstOrDefault(x => x.ContentType.Alias == "home"); if (homePage?.Id > 0) { //save the home page for use later _homePage = homePage; } //get the global site settings page to use var siteSetting = Umbraco.ContentAtRoot().FirstOrDefault(x => x.ContentType.Alias == "siteSettings"); if (siteSetting?.Id > 0) { //get the slider details page var sliderParentsPage = siteSetting.Children().FirstOrDefault(child => child.ContentType.Alias == "sliderItemsContainer"); if (sliderParentsPage?.Id > 0) { //save the slider details page to use later _slidersParentPage = sliderParentsPage; } //get the site details page var siteDetailsPage = siteSetting.Children.FirstOrDefault(child => child.ContentType.Alias == "globalDetails"); if (siteDetailsPage?.Id > 0) { //save the global details page to use later _globalDetailsPage = siteDetailsPage; //get the site name if (siteDetailsPage.HasProperty("siteName") && siteDetailsPage.HasValue("siteName")) { //set the global site name _siteName = siteDetailsPage.GetProperty("siteName").Value().ToString(); } } } //get the local product service to use _productsService = productsService; }
private int GetParentContentId(string childrenAlias) { var listOfRoots = Umbraco.ContentAtRoot(); int rootId = 0; if (listOfRoots != null) { foreach (var root in listOfRoots) { foreach (var item in root.Descendants().Where(x => x.IsDocumentType(childrenAlias))) { rootId = item.Parent.Id; // we asssume, that we have only one root element with Team document type, called Teams break; } } } return(rootId); }
public JToken GetAllRoutes(int?rootId) { var root = rootId.HasValue ? Umbraco.Content(rootId) : Umbraco.ContentAtRoot().First(); var descendants = root.Descendants().ToList(); descendants.Add(root); descendants = _umbracoService.TypeGenericToModelsBuilderType(descendants); // Json settings var jsonSerializerSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ContractResolver = new PublishedContentContractResolver(), }; jsonSerializerSettings.Converters.Add(new HtmlStringConverter()); var data = Newtonsoft.Json.JsonConvert.SerializeObject(descendants, jsonSerializerSettings); return(JToken.Parse(data)); }