/// <summary> /// Updates the translations. /// </summary> /// <param name="node">The node.</param> /// <param name="model">The model.</param> private void UpdateTranslations(SitemapNode node, SaveNodeModel model) { if (model.Translations != null) { foreach (var nodeTranslation in node.Translations) { if (model.Translations.All(m => m.Id != nodeTranslation.Id)) { repository.Delete(nodeTranslation); } } foreach (var translationModel in model.Translations) { var translationToSave = node.Translations.FirstOrDefault(t => t.Id == translationModel.Id); var isNewTranslation = translationToSave == null; if (isNewTranslation) { translationToSave = new Module.Pages.Models.SitemapNodeTranslation { Id = translationModel.Id.GetValueOrDefault(), Node = node }; } else if (translationModel.Version > 0) { translationToSave.Version = translationModel.Version; } translationToSave.Language = this.repository.AsProxy <Language>(translationModel.LanguageId); translationToSave.Macro = translationModel.Macro; translationToSave.Title = translationModel.Title; translationToSave.UsePageTitleAsNodeTitle = translationModel.UsePageTitleAsNodeTitle; translationToSave.Url = translationModel.Url; translationToSave.UrlHash = !string.IsNullOrWhiteSpace(translationToSave.Url) ? translationToSave.Url.UrlHash() : null; if (translationToSave.Node != node) { translationToSave.Node = node; } repository.Save(translationToSave); } } }
/// <summary> /// Updates the translations. /// </summary> /// <param name="node">The node.</param> /// <param name="model">The model.</param> private void UpdateTranslations(SitemapNode node, SaveNodeModel model) { if (model.Translations != null) { foreach (var nodeTranslation in node.Translations) { if (model.Translations.All(m => m.Id != nodeTranslation.Id)) { repository.Delete(nodeTranslation); } } foreach (var translationModel in model.Translations) { var translationToSave = node.Translations.FirstOrDefault(t => t.Id == translationModel.Id); var isNewTranslation = translationToSave == null; if (isNewTranslation) { translationToSave = new Module.Pages.Models.SitemapNodeTranslation { Id = translationModel.Id.GetValueOrDefault(), Node = node }; } else if (translationModel.Version > 0) { translationToSave.Version = translationModel.Version; } translationToSave.Language = this.repository.AsProxy<Language>(translationModel.LanguageId); translationToSave.Macro = translationModel.Macro; translationToSave.Title = translationModel.Title; translationToSave.UsePageTitleAsNodeTitle = translationModel.UsePageTitleAsNodeTitle; translationToSave.Url = translationModel.Url; translationToSave.UrlHash = translationToSave.Url.UrlHash(); if (translationToSave.Node != node) { translationToSave.Node = node; } repository.Save(translationToSave); } } }
private static SaveNodeModel MapSitemapNodeModel(GetNodeResponse response, bool resetIds) { var model = new SaveNodeModel { Id = resetIds ? default(Guid) : response.Data.Id, Version = response.Data.Version, ParentId = response.Data.ParentId, PageId = response.Data.PageId, UsePageTitleAsNodeTitle = response.Data.UsePageTitleAsNodeTitle, Title = response.Data.NodeTitle, Url = response.Data.NodeUrl, DisplayOrder = response.Data.DisplayOrder, Macro = response.Data.Macro, }; if (response.Translations != null) { model.Translations = response.Translations.Select( t => new SaveNodeTranslation { Id = t.Id, Version = t.Version, Title = t.Title, UsePageTitleAsNodeTitle = t.UsePageTitleAsNodeTitle, Url = t.Url, Macro = t.Macro, LanguageId = t.LanguageId }).ToList(); } return model; }