public static async Task <MenuItemBusiness> GetMenuItemAsync(UrlProvider urlProvider, ItemDataModel itemDataModel, ICurrentRequest currentRequest, string moduleName, bool isPrivate = false) { var moduleId = itemDataModel.Id; var freeBusinessModel = (ElementBusinessModel)itemDataModel.Data; var elements = freeBusinessModel.Elements; var title = FreeBusinessModule.GetTitle(elements); var normalizedTitle = UrlHelper.NormalizeTextForUrl(title); var propertyName = itemDataModel.PropertyName; object o = new { title = normalizedTitle, moduleId }; if (isPrivate) { o = new { title = normalizedTitle, moduleId, @private = "privee" }; } var urlInfo = await urlProvider.GetUrlAsync(currentRequest, "Index", moduleName, o); var menuItem = new MenuItemBusiness(); menuItem.Title = title; menuItem.RouteDatas = GetRouteData("Index", moduleName, normalizedTitle, moduleId, propertyName); menuItem.Url = urlInfo.Path; menuItem.RoutePath = urlInfo.RoutePath; menuItem.RoutePathWithoutHomePage = urlInfo.RoutePathWithoutHomePage; menuItem.Route = urlInfo.Route; menuItem.ModuleId = moduleId; menuItem.ModuleName = moduleName; menuItem.Icon = freeBusinessModel.Icon; menuItem.State = itemDataModel.State; menuItem.Seo = new SeoBusiness(); menuItem.Seo.UpdateDate = itemDataModel.UpdateDate.HasValue ? itemDataModel.UpdateDate.Value : itemDataModel.CreateDate; menuItem.Seo.SitemapFrequence = SitemapFrequence.Weekly; menuItem.Seo.SocialImageUrl = FreeBusinessModule.GetFirstImageUrl(itemDataModel.SiteId, freeBusinessModel); var metaKeywords = elements.FirstOrDefault(e => e.Property == "MetaKeyword"); if (metaKeywords != null) { elements.Remove(metaKeywords); } // TODO calculer en automatique menuItem.Seo.MetaKeyword = ""; menuItem.Seo.MetaDescription = FreeBusinessModule.GetMetaDescription(elements); return(menuItem); }
public static async Task <IList <Element> > UpdateElementAsync(string siteId, IList <Element> elements, IItemRepository itemRepository) { //TODO Remove var metaKeywords = elements.FirstOrDefault(e => e.Property == "MetaKeyword"); if (metaKeywords != null) { elements.Remove(metaKeywords); } FreeBusinessModule.UpdateContent(elements, "h1"); FreeBusinessModule.UpdateContent(elements, "p", "Sans text"); // await CleanElementRecursiveAsync(siteId, elements, itemRepository); return(elements); }
private static string GetTitle(ItemDataModel itemDataModel) { var addSiteBusinessModel = (AddSiteBusinessModel)itemDataModel.Data; var title = string.Empty; if (addSiteBusinessModel.Elements != null) { title = FreeBusinessModule.GetTitle(addSiteBusinessModel.Elements); } if (string.IsNullOrEmpty(title)) { title = "Créer votre site"; } return(title); }
private static async Task SendEmailAsync(SiteMap.Site siteInfo, IEmailService _emailService, SiteUserDbModel friendUserDb, ApplicationUser userDb, IList <Element> elements, string siteId) { var model = new MailInvitation() { UserNameSender = userDb.FullName, UserName = friendUserDb.FullName, SiteName = siteInfo.Name, SiteUrl = siteInfo.Url, }; var title = FreeBusinessModule.GetTitle(elements); var identityMessage = new MailMessage(); identityMessage.Subject = new StringTemplateRenderer().Render(title, model); var bodyTemplate = new StringBuilder(); foreach (var element in elements) { bodyTemplate.Append("<div>"); if (element.Type == "p") { bodyTemplate.Append(element.Data); } else if (element.Type == "hr") { bodyTemplate.Append("<hr />"); } else if (SaveFreeCommand.IsFileElementType(element.Type)) { var files = JsonConvert.DeserializeObject <List <DataFileInput> >(element.Data); foreach (var dataFile in files) { var uri = $@"{siteInfo.Url}/api/file/get/{siteId}/{dataFile.Id}/{"ImageThumb"}/{UrlHelper .NormalizeTextForUrl(dataFile.Name)}"; bodyTemplate.Append("<div><img src=\"" + uri + "\" /></div>"); } } bodyTemplate.Append("</div>"); } identityMessage.Body = new StringTemplateRenderer().Render(bodyTemplate.ToString(), model); identityMessage.Destination = friendUserDb.Mail; await _emailService.SendAsync(identityMessage); }
public static async Task <G> GetNewsItemResultAsync <T, G>(IDataFactory dataFactory, UserService userService , ItemDataModel itemDataModel) where T : FreeBusinessModel where G : GetNewsItemBase, new() { var result = await GetFreeResultAsync <T, G>(userService, itemDataModel, dataFactory.ItemRepository); var itemDataModelParent = await dataFactory.ItemRepository.GetItemAsync(itemDataModel.SiteId, itemDataModel.ParentId); var dataParent = (NotificationBusinessModel)itemDataModelParent.Data; var parentTitle = FreeBusinessModule.GetTitle(dataParent.Elements); result.ParentModuleId = itemDataModel.ParentId; result.ModuleId = itemDataModel.Id; result.ParentTitle = parentTitle; return(result); }
public override IDictionary <string, string> GetRootMetadata(GetRootMetaDataInput getRootMetaDataInput) { var itemDataModel = getRootMetaDataInput.ItemDataModel; var moduleId = itemDataModel.Id; var moduleFree = (FreeBusinessModel)itemDataModel.Data; var title = UrlHelper.NormalizeTextForUrl(FreeBusinessModule.GetTitle(moduleFree.Elements)); var routaDatas = new Dictionary <string, string>(); routaDatas.Add("action", "Index"); routaDatas.Add("controller", ModuleName); routaDatas.Add("title", title); routaDatas.Add("moduleId", moduleId.ToString(CultureInfo.InvariantCulture)); return(routaDatas); }