Пример #1
0
        public void ShouldRequireValidStore()
        {
            var commad = new UpdateStoreCommand("aaa", false, "", null);

            FluentActions.Invoking(() =>
                                   SendAsync(commad)).Should().Throw <NotFoundException>();
        }
Пример #2
0
        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());
        }
Пример #3
0
        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));
        }
Пример #4
0
        public async Task <ActionResult <int> > Update(int id, UpdateStoreCommand command)
        {
            if (id != command.Id)
            {
                return(BadRequest());
            }

            return(await Mediator.Send(command));
        }
Пример #5
0
 public void Handle(ICommandContext context, UpdateStoreCommand command)
 {
     context.Get <Store>(command.AggregateRootId).Update(new StoreEditableInfo(
                                                             command.Name,
                                                             command.Description,
                                                             command.Address,
                                                             command.Type
                                                             ));
 }
Пример #6
0
        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>();
        }
Пример #7
0
        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();
        }
Пример #8
0
        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());
        }
Пример #9
0
        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());
        }
Пример #10
0
        public async Task <IActionResult> Put([FromBody] UpdateStoreCommand command)
        {
            var store = await _mediator.Send(command);

            return(Ok(store));
        }