public GetCategoryTreeResponse Get(GetCategoryTreeRequest request)
        {
            var          response = new GetCategoryTreeResponse();
            CategoryTree alias    = null;

            var query = Repository.AsQueryOver(() => alias).Where(() => !alias.IsDeleted);

            if (!string.IsNullOrWhiteSpace(request.SearchQuery))
            {
                var searchQuery = string.Format("%{0}%", request.SearchQuery);
                query =
                    query.Where(Restrictions.Disjunction().Add(Restrictions.InsensitiveLike(NHibernate.Criterion.Projections.Property(() => alias.Title), searchQuery)));
            }

            if (request.WithOrder)
            {
                query = query.AddOrder(request);
            }

            if (request.WithPaging)
            {
                query = query.AddPaging(request);
            }

            response.Items      = query.AddSortingAndPaging(request).Future <CategoryTree>();
            response.TotalCount = query.ToRowCountFutureValue().Value;
            return(response);
        }
        public GetCategoryTreeResponse Get(GetCategoryTreeRequest request)
        {
            var response = new GetCategoryTreeResponse();
            CategoryTree alias = null;

            var query = Repository.AsQueryOver(() => alias).Where(() => !alias.IsDeleted);

            if (!string.IsNullOrWhiteSpace(request.SearchQuery))
            {
                var searchQuery = string.Format("%{0}%", request.SearchQuery);
                query =
                    query.Where(Restrictions.Disjunction().Add(Restrictions.InsensitiveLike(NHibernate.Criterion.Projections.Property(() => alias.Title), searchQuery)));
            }

            if (request.WithOrder)
            {
                query = query.AddOrder(request);
            }

            if (request.WithPaging)
            {
                query = query.AddPaging(request);
            }

            response.Items = query.AddSortingAndPaging(request).Future<CategoryTree>();
            response.TotalCount = query.ToRowCountFutureValue().Value;
            return response;
        }
Example #3
0
        /// <summary>
        /// Gets the category specified in request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        ///   <c>GetCategoriesResponse</c> with category data.
        /// </returns>
        public GetCategoryTreeResponse Get(GetCategoryTreeRequest request)
        {
//            var tagsFuture = repository.AsQueryable<CategoryTag>().Where(e => e.Category.Id == request.CategoryId).Select(e => e.Tag.Name).ToFuture();

            IEnumerable<Module.Root.Models.Category> nodesFuture = null;
            if (request.Data.IncludeNodes)
            {
                 nodesFuture =
                    repository.AsQueryable<Module.Root.Models.Category>()
                        .Where(node => node.CategoryTree.Id == request.CategoryTreeId && !node.IsDeleted)
                        .ToFuture();
            }

            var categorizableItemsFuture = repository.AsQueryable<CategoryTreeCategorizableItem>().Where(c => c.CategoryTree.Id == request.CategoryTreeId).ToFuture();

            var response =
                repository.AsQueryable<CategoryTree>()
                    .Where(s => s.Id == request.CategoryTreeId)
                    .Select(
                        s =>
                        new GetCategoryTreeResponse
                            {
                                Data =
                                    new CategoryTreeModel
                                        {
                                            Id = s.Id,
                                            CreatedBy = s.CreatedByUser,
                                            CreatedOn = s.CreatedOn,
                                            LastModifiedBy = s.ModifiedByUser,
                                            LastModifiedOn = s.ModifiedOn,
                                            Version = s.Version,
                                            Name = s.Title,
                                            Macro = s.Macro
                                        }
                            })
                    .ToFuture()
                    .FirstOne();

//            response.Data.Tags = tagsFuture.ToList();

            if (request.Data.IncludeNodes && nodesFuture != null)
            {
                response.Nodes =
                    nodesFuture.ToList()
                        .Select(
                            node =>
                            new CategoryNodeModel
                                {
                                    Id = node.Id,
                                    Version = node.Version,
                                    CreatedBy = node.CreatedByUser,
                                    CreatedOn = node.CreatedOn,
                                    LastModifiedBy = node.ModifiedByUser,
                                    LastModifiedOn = node.ModifiedOn,
                                    ParentId = node.ParentCategory != null && !node.ParentCategory.IsDeleted ? node.ParentCategory.Id : (Guid?)null,
                                    Name = node.Name,
                                    DisplayOrder = node.DisplayOrder,
                                    Macro = node.Macro,
                                    CategoryTreeId = node.CategoryTree.Id
                                })
                        .Distinct()
                        .ToList();
            }

            var categorizableItems = categorizableItemsFuture.ToList();

            response.Data.AvailableFor = categorizableItems.Select(c => c.CategorizableItem.Id).ToList();
//            if (request.Data.IncludeAccessRules)
//            {
//                response.AccessRules = LoadAccessRules(response.Data.Id);
//            }

            return response;
        }