public async Task <GoodsResponse> Handle(UpdateGoodsCommand request, CancellationToken cancellationToken) { var goods = (await _goodsRepository.GetWithIncludeAsync(request.Id).ConfigureAwait(false)).Data; if (goods == null) { throw new DomainException(ErrorType.GoodsDoesNotExist); } var validate = request.CategoryIds.Select(async x => { if (!(await _categoryRepository.ExistAsync(c => c.Id == x && !c.IsDeleting)).Data) { throw new DomainException(ErrorType.CategoryDoesNotExist); } }); await Task.WhenAll(validate); goods.GoodsCategories.ForEach(x => _goodsCategoryRepository.Delete(x)); await _goodsCategoryRepository.SaveAsync().ConfigureAwait(false); goods.Edit(request); _goodsRepository.Update(goods); await _goodsRepository.SaveAsync().ConfigureAwait(false); var response = (await _goodsRepository.GetWithIncludeAsync(goods.Id).ConfigureAwait(false)).Data.ToResponse(); return(response); }
public static void Edit(this Goods goods, UpdateGoodsCommand command) { goods.Name = command.Name; goods.Currency = command.Currency; goods.Price = command.Price; goods.GoodsCategories = command.CategoryIds.Select(x => new GoodsCategory() { CategoryId = x, GoodsId = command.Id }).ToList(); }
public void Handle(ICommandContext context, UpdateGoodsCommand command) { context.Get <Goods>(command.AggregateRootId).AdminUpdate( new GoodsEditableInfo( command.Name, command.Description, command.Pics, command.Price, command.Benevolence, command.SellOut, command.Status, command.RefusedReason)); }
public async Task <BaseApiResponse> UpdateGoods([FromBody] UpdateGoodsRequest request) { request.CheckNotNull(nameof(request)); 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()) }); } return(new BaseApiResponse()); }
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()); }
public async Task <IActionResult> UpdateGoods([FromBody] UpdateGoodsCommand command) { var result = await _mediator.Send(command); return(JsonResult(result)); }