public void SendContactNotificationToAdmin(ContactFormViewModel vm) { var emailTemplate = GetEmailTemplate("New Contact Form Notification"); if (emailTemplate == null) { throw new Exception("Template not found"); } var subject = emailTemplate.Value <string>("emailTemplateSubjectLine"); var htmlContent = emailTemplate.Value <string>("emailTemplateHtmlContent"); var textContent = emailTemplate.Value <string>("emailTemplateTextContent"); MailMerge("name", vm.Name, ref htmlContent, ref textContent); MailMerge("email", vm.EmailAddress, ref htmlContent, ref textContent); MailMerge("comment", vm.Comment, ref htmlContent, ref textContent); var siteSettings = _umbraco.ContentAtRoot().DescendantsOrSelfOfType("siteSettings").FirstOrDefault(); if (siteSettings == null) { throw new Exception("There are no site settings"); } var toAddresses = siteSettings.Value <string>("emailSettingsAdminAccounts"); if (string.IsNullOrEmpty(toAddresses)) { throw new Exception("There needs to be a to address in site settings"); } SendMail(toAddresses, subject, htmlContent, textContent); }
/// <summary> /// Returns user right menu /// </summary> /// <returns>Hierarchical menu list</returns> public IEnumerable <MemberCenterMenuItem> GetRightMenu() { // Get menu collection root node var rootNode = ((DynamicPublishedContent)_umbracoHelper.ContentAtRoot().First()) .DescendantsOrSelf("MemberCenterRightMenuCollection").First(); // Get the list of all menu items that have proper user rights // List has flat structure, next step is to build hierarchy var flatList = ((DynamicPublishedContent)_umbracoHelper.ContentAtRoot().First()) .Descendants("MemberCenterRightMenuItem") .Where(UserHasAccess) .Select(_ => new MemberCenterMenuItem() { Id = _.Id, ParentId = _.Parent.Id, Title = _.Name, Url = _umbracoHelper.NiceUrl(_.GetPropertyValue <int>("pageLink")), Description = _.GetPropertyValue <string>("description") }); // Build hierarchical menu // Show items that have subitems or description // Empty items will be skiped var result = BuildMenuTree(rootNode.Id, flatList) .Where(_ => _.Items.Any() || !String.IsNullOrEmpty(_.Description)); return(result); }
/// <summary> /// Returns the email template as IPublishedContent where the title matches the template name /// </summary> /// <param name="templateName"></param> /// <returns></returns> private IPublishedContent GetEmailTemplate(string templateName) { var template = _umbraco.ContentAtRoot() .DescendantsOrSelfOfType("emailTemplate") .Where(w => w.Name == templateName) .FirstOrDefault(); return(template); }
public VideoList GetVideoListPage(UmbracoHelper umbracoHelper) { var siteRoot = umbracoHelper.ContentAtRoot().Where(x => x.Name == "Home").FirstOrDefault(); var videoListPage = siteRoot.DescendantsOrSelf <VideoList>().FirstOrDefault(); return(videoListPage); }
public void SendContactNotificationToAdmin(ContactFormViewModel vm) { //Get email template from Umbraco for "this" notification is var emailTemplate = GetEmailTemplate("New Contact Form Notification"); if (emailTemplate == null) { throw new Exception("Template not found"); } //Get the template data var subject = emailTemplate.Value <string>("emailTemplateSubjectLine"); var htmlContent = emailTemplate.Value <string>("emailTemplateHtmlContent"); var textContent = emailTemplate.Value <string>("emailTemplateTextContent"); //Mail merge the necessary fields //#name## MailMerge("name", vm.Name, ref htmlContent, ref textContent); //#email## MailMerge("email", vm.EmailAddress, ref htmlContent, ref textContent); //#comment## MailMerge("comment", vm.Comment, ref htmlContent, ref textContent); //Send email out to whoever //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 toAddresses = siteSettings.Value <string>("emailSettingsAdminAccounts"); if (string.IsNullOrEmpty(toAddresses)) { throw new Exception("There needs to be a to address in site settings"); } SendMail(toAddresses, subject, htmlContent, textContent); }
public bool TryFindContent(PublishedContentRequest contentRequest) { var umbracoHelper = new UmbracoHelper(contentRequest.RoutingContext.UmbracoContext); var home = umbracoHelper.ContentAtRoot().FirstOrDefault(); // Catch all requests and leave to React Router to handle contentRequest.PublishedContent = umbracoHelper.TypedContent(home.Id); return(true); }
public IEnumerable <SubCategory> GetAll() { var cachedHomeNode = _umbraco.ContentAtRoot(); if (cachedHomeNode != null) { var subCategories = cachedHomeNode.DescendantsOrSelfOfType(NodeAliasConstants.SubCategory); if (subCategories != null && subCategories.Any()) { return(subCategories.Select(x => new SubCategory(x))); } } return(null); }
/// <summary> /// Get all Shops /// </summary> /// <returns>Returns All published Shops</returns> public IEnumerable <Shop> GetAll() { var cachedHomeNode = _umbraco.ContentAtRoot(); if (cachedHomeNode != null) { var shops = cachedHomeNode.DescendantsOrSelfOfType(NodeAliasConstants.Shop); if (shops.IsNotNullOrEmpty()) { return(shops.Select(x => new Shop(x))); } } return(null); }
public IEnumerable <MasterCategory> GetAll() { var cachedHomeNode = _umbraco.ContentAtRoot(); if (cachedHomeNode != null) { var masterCategories = cachedHomeNode.DescendantsOrSelfOfType(NodeAliasConstants.MasterCategory); if (masterCategories.IsNotNullOrEmpty()) { return(masterCategories.Select(x => new MasterCategory(x))); } } return(null); }
public IEnumerable <MemberAnnouncement> GetList() { // Get the list of announcements that are visible var result = ((DynamicPublishedContent)_helper.ContentAtRoot().First()) .DescendantsOrSelf("MemberCenterAnnouncementItem") .Where(_ => _.GetPropertyValue <bool>("visible")) .Select(_ => new MemberAnnouncement() { Title = _.GetPropertyValue <string>("title"), ShortMessage = _.GetPropertyValue <string>("shortMessage"), FullMessage = _.GetPropertyValue <string>("fullMessage"), Url = _.Url }); return(result); }
public List <Form> GetForms() { List <Form> forms = new List <Form>(); foreach (IPublishedContent root in umbracoHelper.ContentAtRoot()) { if (!root.DocumentTypeAlias.Equals(NodeAlias.FormCollection)) { continue; } var query = root.Children.Where(n => n.DocumentTypeAlias.Equals(NodeAlias.FormNode)).Select(cn => new Form() { Id = cn.Id, Name = cn.Name }); return(query.ToList()); } return(forms); }
private static IPublishedContent GetGroupsRootFolder(UmbracoHelper helper) { return(helper.ContentAtRoot() .FirstOrDefault(x => x.IsDocumentType(AppConstants.DocumentTypeAliases.PersonalisationGroupsFolder))); }
public JsonResult Get(SearchRequest model) { SearchSettings settings = SettingsRepository.Get(); SearchResponse SearchResponse = new SearchResponse(); RootObject obj = new RootObject(); bool retry = false; String FormattedQuery = model.Query; String DevelopmentURL = settings.DevelopmentURL; JsonResult json = new JsonResult(); if (ValidateSettings(settings)) { //https://stackoverflow.com/questions/30611114/google-custom-search-engine-result-counts-changing-as-results-are-paged do { retry = false; IPublishedContent currentNode = UmbracoContext.ContentCache.GetById(model.CurrentNodeID); IPublishedContent rootNode = uh.ContentAtRoot().FirstOrDefault(t => t.GetCulture().Culture == NodeService.GetCurrentCulture(currentNode).Culture); if (rootNode == null) { rootNode = currentNode.AncestorsOrSelf(2).FirstOrDefault(); } if (!String.IsNullOrEmpty(model.Section)) { IPublishedContent node = rootNode.Descendant(model.Section); if (node != null) { FormattedQuery = String.Format("{0} site:{1}", model.Query, !String.IsNullOrEmpty(DevelopmentURL) ? Regex.Replace(node.UrlAbsolute(), @"http.*:\/\/" + HttpContext.Request.Url.DnsSafeHost, DevelopmentURL) : node.UrlAbsolute()); } } else { FormattedQuery = String.Format("{0} site:{1}", model.Query, !String.IsNullOrEmpty(DevelopmentURL) ? DevelopmentURL : rootNode.UrlAbsolute()); } if (!String.IsNullOrEmpty(model.FileType)) { FormattedQuery = String.Format("{0} filetype:{1}", FormattedQuery, model.FileType); } string URL = string.Format("{0}?filter=1&key={1}&cx={2}&q={3}&start={4}&num={5}&prettyPrint=false", settings.BaseURL, settings.APIKey, settings.CXKey, FormattedQuery, model.StartIndex, settings.ItemsPerPage); if (settings.DateRestrict != null && settings.DateRestrict.Value != null && String.IsNullOrEmpty(model.FileType)) { URL += String.Format("&dateRestrict=d{0}", Math.Abs((DateTime.Now - settings.DateRestrict.Value).Days)); } SearchResponse = SearchRequest(URL); obj = JsonConvert.DeserializeObject <RootObject>(SearchResponse.Response); if (obj != null) { retry = int.Parse(obj.searchInformation.totalResults) == 0 && model.StartIndex > 0 ? !retry : retry; model.StartIndex = retry ? model.StartIndex - settings.ItemsPerPage : model.StartIndex; } } while (int.Parse(obj.searchInformation.totalResults) == 0 && model.StartIndex > 1 && retry); if (settings != null && obj != null && obj.items != null && !String.IsNullOrEmpty(settings.ExcludeNodeIds)) { List <String> urls = NodeService.GetAbsoluteURLByUdi(settings.ExcludeNodeIds); if (urls != null) { foreach (var url in urls) { String _url = url; if (!String.IsNullOrEmpty(DevelopmentURL)) { _url = Regex.Replace(_url, @"http.*:\/\/" + HttpContext.Request.Url.DnsSafeHost, DevelopmentURL); } Item item = obj.items.FirstOrDefault(i => i.link == _url); if (item != null) { obj.items.Remove(item); } } } } String TopResultURL = obj.items != null && obj.items.Count > 0 && obj.items.First() != null?obj.items.First().formattedUrl : ""; if (obj.spelling != null && !String.IsNullOrEmpty(obj.spelling.correctedQuery)) { obj.spelling.correctedQuery = obj.spelling.correctedQuery.Replace(String.Format("site:{0}", DevelopmentURL), ""); } SearchEntry SearchEntry = QueriesRepository.Create(new SearchEntry() { Query = model.Query, Date = DateTime.Now, TotalCount = int.Parse(obj.searchInformation.totalResults), Timing = double.Parse(obj.searchInformation.formattedSearchTime), TopResultURL = TopResultURL, CorrectedQuery = obj.spelling != null ? obj.spelling.correctedQuery : "" }); json = new JsonResult() { JsonRequestBehavior = JsonRequestBehavior.AllowGet, Data = new { success = SearchResponse.Success, list = RenderViewService.GetRazorViewAsString(obj, "~/App_Plugins/W3S_GCS/Views/Partials/SearchResults.cshtml"), spelling = settings.ShowSpelling && obj.spelling != null && !String.IsNullOrEmpty(obj.spelling.correctedQuery) ? RenderViewService.GetRazorViewAsString(new SpellingModel() { CorrectedQuery = obj.spelling.correctedQuery, SearchURL = settings.RedirectNodeURL }, "~/App_Plugins/W3S_GCS/Views/Partials/SearchSpelling.cshtml") : "", totalCount = obj.searchInformation.totalResults, timing = obj.searchInformation.formattedSearchTime, totalPages = Math.Ceiling((double)int.Parse(obj.searchInformation.totalResults) / int.Parse(settings.ItemsPerPage.ToString())), pagination = settings.LoadMoreSetUp == "pagination" ? RenderViewService.GetRazorViewAsString(PaginationService.GetPaginationModel(Request, obj, settings.ItemsPerPage, model.StartIndex, model.Query, model.FileType, model.Section, settings.MaxPaginationPages), "~/App_Plugins/W3S_GCS/Views/Partials/SearchPagination.cshtml") : "", filetypefilter = settings.ShowFilterFileType ? RenderViewService.GetRazorViewAsString(new FileTypeFilter(), "~/App_Plugins/W3S_GCS/Views/Partials/SearchFileTypeFilterSelect.cshtml") : "", queryId = SearchEntry.Id } }; } return(json); }