public bool Delete(DeleteCategoryTreeRequest request)
        {
            var entityCategorysFuture = Repository
                                        .AsQueryable <IEntityCategory>()
                                        .Where(t => t.Category.CategoryTree.Id == request.Id)
                                        .ToFuture();
            var categoryTreeFuture = Repository
                                     .AsQueryable <CategoryTree>()
                                     .Where(t => t.Id == request.Id)
                                     .ToFuture();
            var children = Repository
                           .AsQueryable <Category>()
                           .Where(t => t.CategoryTree.Id == request.Id)
                           .ToFuture()
                           .ToList();
            var entityCategorys = entityCategorysFuture.ToList();

            var categoryTree = categoryTreeFuture.First();


            if (request.Version > 0 && categoryTree.Version != request.Version)
            {
                throw new ConcurrentDataException(categoryTree);
            }


            UnitOfWork.BeginTransaction();

            Repository.Delete(categoryTree);
            foreach (var category in children)
            {
                Repository.Delete(category);
            }
            foreach (var categorys in entityCategorys)
            {
                Repository.Delete(categorys);
            }

            UnitOfWork.Commit();


            RootEvents.Instance.OnCategoryTreeDeleted(categoryTree);
            return(true);
        }
        public bool Delete(DeleteCategoryTreeRequest request)
        {
            var categoryTree = Repository
                               .AsQueryable <CategoryTree>()
                               .Where(map => map.Id == request.Id)
                               // TODO:                .FetchMany(map => map.AccessRules)
                               .Distinct()
                               .ToList()
                               .First();

            // TODO:            // Security.
            //            if (cmsConfiguration.Security.AccessControlEnabled)
            //            {
            //                var roles = new[] { RootModuleConstants.UserRoles.EditContent };
            //                accessControlService.DemandAccess(sitemap, currentUser, AccessLevel.ReadWrite, roles);
            //            }

            // Concurrency.
            if (request.Version > 0 && categoryTree.Version != request.Version)
            {
                throw new ConcurrentDataException(categoryTree);
            }

            UnitOfWork.BeginTransaction();

            // TODO:
            //            if (sitemap.AccessRules != null)
            //            {
            //                var rules = sitemap.AccessRules.ToList();
            //                rules.ForEach(sitemap.RemoveRule);
            //            }

            Repository.Delete(categoryTree);

            UnitOfWork.Commit();

            RootEvents.Instance.OnCategoryTreeDeleted(categoryTree);
            // Events.
            // TODO:            Events.SitemapEvents.Instance.OnSitemapDeleted(categoryTree);
            return(true);
        }
        public bool Delete(DeleteCategoryTreeRequest request)
        {
            var entityCategorysFuture = Repository
                .AsQueryable<IEntityCategory>()
                .Where(t => t.Category.CategoryTree.Id == request.Id)
                .ToFuture();
            var categoryTreeFuture = Repository
                .AsQueryable<CategoryTree>()
                .Where(t => t.Id == request.Id)
                .ToFuture();
            var children = Repository
                .AsQueryable<Category>()
                .Where(t=>t.CategoryTree.Id == request.Id)
                .ToFuture()
                .ToList();
            var entityCategorys = entityCategorysFuture.ToList();

            var categoryTree = categoryTreeFuture.First();

            if (request.Version > 0 && categoryTree.Version != request.Version)
            {
                throw new ConcurrentDataException(categoryTree);
            }

            UnitOfWork.BeginTransaction();

            Repository.Delete(categoryTree);
            foreach (var category in children)
            {
                Repository.Delete(category);
            }
            foreach (var categorys in entityCategorys)
            {
                Repository.Delete(categorys);
            }

            UnitOfWork.Commit();

            RootEvents.Instance.OnCategoryTreeDeleted(categoryTree);
            return true;
        }
        public bool Delete(DeleteCategoryTreeRequest request)
        {
            var categoryTree = Repository
                .AsQueryable<CategoryTree>()
                .Where(map => map.Id == request.Id)
                // TODO:                .FetchMany(map => map.AccessRules)
                .Distinct()
                .ToList()
                .First();

            // TODO:            // Security.
            //            if (cmsConfiguration.Security.AccessControlEnabled)
            //            {
            //                var roles = new[] { RootModuleConstants.UserRoles.EditContent };
            //                accessControlService.DemandAccess(sitemap, currentUser, AccessLevel.ReadWrite, roles);
            //            }

            // Concurrency.
            if (request.Version > 0 && categoryTree.Version != request.Version)
            {
                throw new ConcurrentDataException(categoryTree);
            }

            UnitOfWork.BeginTransaction();

            // TODO:
            //            if (sitemap.AccessRules != null)
            //            {
            //                var rules = sitemap.AccessRules.ToList();
            //                rules.ForEach(sitemap.RemoveRule);
            //            }

            Repository.Delete(categoryTree);

            UnitOfWork.Commit();

            RootEvents.Instance.OnCategoryTreeDeleted(categoryTree);
            // Events.
            // TODO:            Events.SitemapEvents.Instance.OnSitemapDeleted(categoryTree);
            return true;
        }
Пример #5
0
        /// <summary>
        /// Deletes the category specified in request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        ///   <c>DeleteCategoriesResponse</c> with success status.
        /// </returns>
        public DeleteCategoryTreeResponse Delete(DeleteCategoryTreeRequest request)
        {
            if (request.Data == null || request.Id.HasDefaultValue())
            {
                return new DeleteCategoryTreeResponse { Data = false };
            }

            categoryTreeService.Delete(
                new Module.Root.Services.Categories.Tree.DeleteCategoryTreeRequest
                {
                    Id = request.Id,
                    CurrentUser = securityService.GetCurrentPrincipal(),
                    Version = request.Data.Version
                });

            return new DeleteCategoryTreeResponse { Data = true };
        }