Пример #1
0
        public async Task <BaseApiResponse> GoodsPublish(InfoRequest request)
        {
            request.CheckNotNull(nameof(request));
            var goodsAlis = _goodsQueryService.GetGoodsAlias(request.Id);

            if (goodsAlis == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "未找到商品"
                });
            }
            var command = new PublishGoodsCommand
            {
                AggregateRootId = request.Id
            };
            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            return(new BaseApiResponse());
        }
Пример #2
0
        public async Task <BaseApiResponse> UpdateGoods(UpdateGoodsRequest request)
        {
            request.CheckNotNull(nameof(request));
            var goods = _goodsQueryService.GetGoodsAlias(request.Id);

            if (goods == null)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "未找到该商品"
                });
            }
            var command = new UpdateGoodsCommand(
                request.Name,
                request.Description,
                request.Pics,
                request.Price,
                request.Benevolence,
                request.SellOut,
                request.Status,
                request.RefusedReason)
            {
                AggregateRootId = request.Id
            };

            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "更新商品失败:{0}".FormatWith(result.GetErrorMessage())
                });
            }
            //更新规格
            var command2 = new UpdateSpecificationsCommand(
                request.Id,
                request.Specifications.Select(x => new Commands.Goodses.Specifications.SpecificationInfo(
                                                  x.Id,
                                                  x.Name,
                                                  x.Value,
                                                  x.Thumb,
                                                  x.Price,
                                                  x.OriginalPrice,
                                                  x.Benevolence,
                                                  x.Number,
                                                  x.BarCode,
                                                  x.Stock
                                                  )).ToList(),
                true);
            var result2 = await ExecuteCommandAsync(command2);

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

            RecordOperat(currentAdmin.AdminId.ToGuid(), "审核商品", request.Id, goods.Name);

            return(new BaseApiResponse());
        }