private static SaveSitemapNodeModel ToModel(SitemapNodeWithTranslationsModel n, bool resetIds)
        {
            var model = new SaveSitemapNodeModel
                            {
                                Id = resetIds ? default(Guid) : n.Id,
                                Version = n.Version,
                                PageId = n.PageId,
                                UsePageTitleAsNodeTitle = n.UsePageTitleAsNodeTitle,
                                Title = n.NodeTitle,
                                Url = n.NodeUrl,
                                DisplayOrder = n.DisplayOrder,
                                Macro = n.Macro
                            };

            if (n.Translations != null)
            {
                model.Translations =
                    n.Translations.Select(
                        t =>
                        new SaveSitemapNodeTranslation
                            {
                                Id = t.Id,
                                Version = t.Version,
                                Title = t.Title,
                                UsePageTitleAsNodeTitle = t.UsePageTitleAsNodeTitle,
                                Url = t.Url,
                                Macro = t.Macro,
                                LanguageId = t.LanguageId
                            }).ToList();
            }

            return model;
        }
Example #2
0
        /// <summary>
        /// Saves the translations.
        /// </summary>
        /// <param name="model">The node model.</param>
        /// <param name="node">The node to save.</param>
        private void SaveTranslations(SaveSitemapNodeModel model, SitemapNode node)
        {
            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 = 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);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Saves the translations.
        /// </summary>
        /// <param name="model">The node model.</param>
        /// <param name="node">The node to save.</param>
        private void SaveTranslations(SaveSitemapNodeModel model, SitemapNode node)
        {
            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 = 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);
                }
            }
        }