Exemple #1
0
        /// <summary>
        /// Puts the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        ///   <c>PutNodeResponse</c> with create or updated node id.
        /// </returns>
        public PutNodeResponse Put(PutNodeRequest request)
        {
            var categoryFuture = repository.AsQueryable<CategoryTree>(e => e.Id == request.CategoryTreeId)
//                .FetchMany(f => f.AccessRules)
                .ToFuture();

            var node =
                repository.AsQueryable<Module.Root.Models.Category>(e => e.CategoryTree.Id == request.CategoryTreeId && e.Id == request.Id)
//                    .FetchMany(n => n.Translations)
//                    .ToFuture()
//                    .ToList()
                    .FirstOrDefault();

            var category = categoryFuture.ToList().FirstOne();

//            if (cmsConfiguration.Security.AccessControlEnabled)
//            {
//                accessControlService.DemandAccess(category, securityService.GetCurrentPrincipal(), AccessLevel.ReadWrite);
//            }

            var isNew = node == null;
            if (isNew)
            {
                node = new Module.Root.Models.Category
                              {
                                  Id = request.Id.GetValueOrDefault()
                              };
            }
            else if (request.Data.Version > 0)
            {
                node.Version = request.Data.Version;
            }

            unitOfWork.BeginTransaction();

//            categoryService.ArchiveCategory(category.Id);

            node.CategoryTree = category;
            node.Name = request.Data.Name;

            node.ParentCategory = request.Data.ParentId.GetValueOrDefault() != default(Guid)
                                  ? repository.AsProxy<Module.Root.Models.Category>(request.Data.ParentId.GetValueOrDefault())
                                  : null;

            node.DisplayOrder = request.Data.DisplayOrder;
            node.Macro = request.Data.Macro;

            repository.Save(node);

            unitOfWork.Commit();

            // Fire events.
            if (isNew)
            {
                Events.RootEvents.Instance.OnCategoryCreated(node);
            }
            else
            {
                Events.RootEvents.Instance.OnCategoryUpdated(node);
            }

            Events.RootEvents.Instance.OnCategoryTreeUpdated(category);

            return new PutNodeResponse { Data = node.Id };
        }
Exemple #2
0
        /// <summary>
        /// Puts the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        ///   <c>PutNodeResponse</c> with create or updated node id.
        /// </returns>
        public PutNodeResponse Put(PutNodeRequest request)
        {
            var sitemapFuture = repository.AsQueryable<Module.Pages.Models.Sitemap>(e => e.Id == request.SitemapId)
                .FetchMany(f => f.AccessRules)
                .ToFuture();

            var node =
                repository.AsQueryable<SitemapNode>(e => e.Sitemap.Id == request.SitemapId && e.Id == request.Id)
                    .FetchMany(n => n.Translations)
                    .ToFuture()
                    .ToList()
                    .FirstOrDefault();

            var sitemap = sitemapFuture.ToList().FirstOne();

            if (cmsConfiguration.Security.AccessControlEnabled)
            {
                accessControlService.DemandAccess(sitemap, securityService.GetCurrentPrincipal(), AccessLevel.ReadWrite);
            }

            var isNew = node == null;
            if (isNew)
            {
                node = new SitemapNode
                              {
                                  Id = request.Id.GetValueOrDefault(),
                                  Translations = new List<Module.Pages.Models.SitemapNodeTranslation>()
                              };
            }
            else if (request.Data.Version > 0)
            {
                node.Version = request.Data.Version;
            }

            unitOfWork.BeginTransaction();

            sitemapService.ArchiveSitemap(sitemap.Id);

            node.Sitemap = sitemap;
            node.Title = request.Data.Title;
            if (request.Data.PageId.GetValueOrDefault() != default(Guid))
            {
                node.Page = repository.AsProxy<PageProperties>(request.Data.PageId.GetValueOrDefault());
                node.Url = null;
                node.UrlHash = null;
            }
            else
            {
                node.Page = null;
                node.Url = request.Data.Url;
                node.UrlHash = node.Url.UrlHash();
            }

            node.ParentNode = request.Data.ParentId.GetValueOrDefault() != default(Guid)
                                  ? repository.AsProxy<SitemapNode>(request.Data.ParentId.GetValueOrDefault())
                                  : null;

            node.DisplayOrder = request.Data.DisplayOrder;
            node.Macro = request.Data.Macro;
            node.UsePageTitleAsNodeTitle = request.Data.UsePageTitleAsNodeTitle;

            repository.Save(node);

            UpdateTranslations(node, request.Data);

            unitOfWork.Commit();

            // Fire events.
            if (isNew)
            {
                Events.SitemapEvents.Instance.OnSitemapNodeCreated(node);
            }
            else
            {
                Events.SitemapEvents.Instance.OnSitemapNodeUpdated(node);
            }

            Events.SitemapEvents.Instance.OnSitemapUpdated(sitemap);

            return new PutNodeResponse { Data = node.Id };
        }