public void Handle(ICommandContext context, UpdateSpecificationCommand command) { context.Get <Goods>(command.AggregateRootId).UpdateSpecification( command.SpecificationId, new Domain.Models.Goodses.Specifications.SpecificationInfo( command.Name, command.Value, command.Thumb, command.Price, command.OriginalPrice, command.Benevolence, command.Number, command.BarCode), command.Stock); }
public async Task <BaseApiResponse> StoreUpdateGoods(AddGoodsRequest request) { request.CheckNotNull(nameof(request)); TryInitUserModel(); var command = new StoreUpdateGoodsCommand( request.CategoryIds, request.Name, request.Description, request.Pics, request.Price, request.OriginalPrice, request.Stock, request.IsPayOnDelivery, request.IsInvoice, request.Is7SalesReturn, request.Sort) { AggregateRootId = request.Id }; var result = await ExecuteCommandAsync(command); if (!result.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } //更新默认规格 var specification = _goodsQueryService.GetGoodsDefaultSpecification(request.Id); if (specification != null) { var thumb = specification.Thumb; if (request.Pics.Any()) { thumb = request.Pics[0]; } //更新默认规格 var command2 = new UpdateSpecificationCommand( request.Id, specification.Id, "默认规格", "默认规格", thumb, request.Price, request.OriginalPrice, request.OriginalPrice / 100M, "", "", request.Stock); var result2 = await ExecuteCommandAsync(command2); if (!result2.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } } return(new BaseApiResponse()); }
public async Task <ActionResult <SpecificationViewModel> > UpdateSpecificationAsync(int id, UpdateSpecificationCommand updateSpecificationCommand) { var existingSpecificationViewModel = await _queries.FindByIdAsync(id); var existingCategory = await _categoryQueries.FindByIdAsync(updateSpecificationCommand.CategoryId); if (existingSpecificationViewModel == null || existingCategory == null) { return(NotFound()); } var specification = _mapper.Map <Specification>(existingSpecificationViewModel); _mapper.Map(updateSpecificationCommand, specification); await _behavior.UpdateSpecificationAsync(specification); var specificationViewModel = await _queries.FindByIdAsync(specification.Id); return(specificationViewModel); }