public void ShouldRequireValidStore() { var commad = new UpdateStoreCommand("aaa", false, "", null); FluentActions.Invoking(() => SendAsync(commad)).Should().Throw <NotFoundException>(); }
public async Task <BaseApiResponse> Edit(AdminEditRequest request) { request.CheckNotNull(nameof(request)); var command = new UpdateStoreCommand( request.Name, request.Description, request.Address, request.Type, request.IsLocked) { AggregateRootId = request.Id }; var result = await ExecuteCommandAsync(command); if (!result.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } //添加操作记录 var currentAdmin = _contextService.GetCurrentAdmin(HttpContext.Current); RecordOperat(currentAdmin.AdminId.ToGuid(), "编辑店铺", request.Id, request.Name); return(new BaseApiResponse()); }
public async Task <Store> UpdateStoreAsync([GraphQLType(typeof(UpdateStoreInputType))][GraphQLName("input")] UpdateStoreCommand input, [Service] ISheaftMediatr mediatr, StoresByIdBatchDataLoader storesDataLoader, CancellationToken token) { await ExecuteAsync(mediatr, input, token); return(await storesDataLoader.LoadAsync(input.StoreId, token)); }
public async Task <ActionResult <int> > Update(int id, UpdateStoreCommand command) { if (id != command.Id) { return(BadRequest()); } return(await Mediator.Send(command)); }
public void Handle(ICommandContext context, UpdateStoreCommand command) { context.Get <Store>(command.AggregateRootId).Update(new StoreEditableInfo( command.Name, command.Description, command.Address, command.Type )); }
public async Task ShouldRequireDescription() { var ownerId = await GetRandomOwner(); var storeId = await GetRandomStore(ownerId); var command = new UpdateStoreCommand(storeId, false, null, null); FluentActions.Invoking(() => SendAsync(command)).Should().Throw <ValidationException>(); }
public async Task ShouldUpdate() { var ownerId = await GetRandomOwner(); var storeId = await GetRandomStore(ownerId); var command = new UpdateStoreCommand(storeId, true, "A great description \nfor this store!", null); await SendAsync(command); var store = await FindAsync <Store>(storeId); store.Published.Should().BeTrue(); store.Description.Should().Be("A great description \nfor this store!"); store.Catalogue.Should().NotBeNull(); }
public async Task <IActionResult> UpdateStore([FromBody] UpdateStoreContract updateStoreContract) { var model = storeUpdateConverter.ToDomain(updateStoreContract); var command = new UpdateStoreCommand(model); try { await commandDispatcher.DispatchAsync(command, default); } catch (DomainException e) { return(BadRequest(e.Reason)); } return(Ok()); }
public async Task <BaseApiResponse> Edit([FromBody] AdminEditRequest request) { request.CheckNotNull(nameof(request)); var command = new UpdateStoreCommand( request.Name, request.Description, request.Address, request.Type) { AggregateRootId = request.Id }; var result = await ExecuteCommandAsync(command); if (!result.IsSuccess()) { return(new BaseApiResponse { Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage()) }); } return(new BaseApiResponse()); }
public async Task <IActionResult> Put([FromBody] UpdateStoreCommand command) { var store = await _mediator.Send(command); return(Ok(store)); }