public void Handle(ICommandContext context, AddSpecificationsCommand command) { context.Get <Goods>(command.AggregateRootId).AddSpecifications(command.Specifications.Select(x => new Domain.Models.Goodses.Specifications.Specification( x.Id, new Domain.Models.Goodses.Specifications.SpecificationInfo( x.Name, x.Value, x.Thumb, x.Price, x.OriginalPrice, x.Benevolence, x.Number, x.BarCode ), x.Stock)).ToList()); }
public async Task <BaseApiResponse> AddGoodsSpecifications(AddGoodsSpecificationsRequest request) { request.CheckNotNull(nameof(request)); //获取商品,现在商品的规格图片为商品的第一张图片 var goodsAlis = _goodsQueryService.GetGoodsAlias(request.GoodsId); if (goodsAlis == null) { return(new BaseApiResponse { Code = 400, Message = "没找到该商品" }); } var thumbs = goodsAlis.Pics.Split("|", true); var thumb = ""; if (thumbs.Any()) { thumb = thumbs[0]; } var command = new AddSpecificationsCommand(request.GoodsId, request.Specifications.Select(x => new Commands.Goodses.Specifications.SpecificationInfo( GuidUtil.NewSequentialId(), x.Name.ExpandAndToString(), x.Value.ExpandAndToString(), thumb, x.Price, x.OriginalPrice, 0, x.Number, x.BarCode, x.Stock)).ToList()); var result = await ExecuteCommandAsync(command); if (!result.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } return(new BaseApiResponse()); }