Example #1
0
        public async Task <BaseApiResponse> Delete([FromBody] DeleteRequest request)
        {
            request.CheckNotNull(nameof(request));
            //分类判断
            var category = _pubCategoryQueryService.Find(request.Id);

            if (category == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该分类"
                });
            }
            //判断是否有子分类
            var children = _pubCategoryQueryService.GetChildren(request.Id);

            if (children.Any())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "包含子分类,无法删除"
                });
            }
            //删除
            var command = new DeletePubCategoryCommand(request.Id);
            var result  = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new BaseApiResponse());
        }
Example #2
0
        public BaseApiResponse CategoryTree()
        {
            //递归获取分类包含子类
            Func <PubCategory, object> getNodeData = null;

            getNodeData = cat => {
                dynamic node = new ExpandoObject();
                node.Id       = cat.Id;
                node.Name     = cat.Name;
                node.Thumb    = cat.Thumb;
                node.IsShow   = cat.IsShow;
                node.Sort     = cat.Sort;
                node.Children = new List <dynamic>();

                var childrens = _pubCategoryQueryService.GetChildren(cat.Id).Where(x => x.IsShow).OrderByDescending(x => x.Sort);
                foreach (var child in childrens)
                {
                    node.Children.Add(getNodeData(child));
                }
                return(node);
            };

            List <PubCategory> rootsCategory = _pubCategoryQueryService.RootCategorys().Where(x => x.IsShow).OrderByDescending(x => x.Sort).ToList();
            List <object>      nodes         = rootsCategory.Select(getNodeData).ToList();

            return(new PubCategoryTreeResponse
            {
                Categorys = nodes
            });
        }
Example #3
0
        public async Task <BaseApiResponse> Delete(DeleteRequest request)
        {
            request.CheckNotNull(nameof(request));
            //分类判断
            var category = _pubCategoryQueryService.Find(request.Id);

            if (category == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "没找到该分类"
                });
            }
            //判断是否有子分类
            var children = _pubCategoryQueryService.GetChildren(request.Id);

            if (children.Any())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "包含子分类,无法删除"
                });
            }
            //删除
            var command = new DeletePubCategoryCommand(request.Id);
            var result  = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            //添加操作记录
            var currentAdmin = _contextService.GetCurrentAdmin(HttpContext.Current);

            RecordOperat(currentAdmin.AdminId.ToGuid(), "删除发布分类", request.Id, category.Name);
            return(new BaseApiResponse());
        }