public static Goods ToModel(this CreateGoodsCommand command) => new Goods { Name = command.Name, Currency = command.Currency, Price = command.Price, GoodsCategories = command.CategoryIds.Select(x => x.ToModel()).ToList() };
public async Task <BaseApiResponse> AddGoods(AddGoodsRequest request) { request.CheckNotNull(nameof(request)); TryInitUserModel(); //创建商品 var goodsId = GuidUtil.NewSequentialId(); var command = new CreateGoodsCommand( goodsId, request.StoreId, request.CategoryIds, request.Name, request.Description, request.Pics, request.Price, request.OriginalPrice, request.Stock, request.IsPayOnDelivery, request.IsInvoice, request.Is7SalesReturn, request.Sort); var result = await ExecuteCommandAsync(command); if (!result.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } //初始化默认规格 var thumb = ""; if (request.Pics.Any()) { thumb = request.Pics[0]; } var command2 = new AddSpecificationCommand( goodsId, "默认规格", "默认规格", thumb, request.Price, request.Stock, request.OriginalPrice, request.OriginalPrice / 100M, "", ""); var result2 = await ExecuteCommandAsync(command2); if (!result2.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } return(new AddGoodsResponse { GoodsId = goodsId }); }
public void Post() { var createGoodsCommand = new CreateGoodsCommand("Table", 120, 80, 10, "Work Desk.", 10); var commandBus = ServiceLocator.Current.Resolve <ICommandBus>(); commandBus.Dispatch(createGoodsCommand); }
public void Save(CreateGoodsCommand model) { //Bus.Dispatch(model); }
public void CreateGoods(CreateGoodsCommand command) { CommandBus.Dispatch(command); }
public async Task <IActionResult> CreateGoods([FromBody] CreateGoodsCommand command) { var result = await _mediator.Send(command); return(JsonResult(result)); }