Exemplo n.º 1
0
        public async Task <IActionResult> ChangeProductQuantityAsync(string id, string productId, int quantity)
        {
            var command       = new ChangeProductQuantityCommand(id, productId, quantity);
            var commandResult = await mediator.Send(command);

            if (commandResult.WasSuccessful)
            {
                return(RedirectToAction(nameof(DetailsAsync), new { id }));
            }

            var viewModel = await GetCartDetailsViewModel(id);

            viewModel.AddMessage(MessageModel.Alert(commandResult.BrokenRules.First().Message));

            return(View(nameof(DetailsAsync), viewModel));
        }
        public ChangeProductQuantityCommandHandlerTest()
        {
            basketRedisService = new Mock <IBasketRedisService>();
            command            = new ChangeProductQuantityCommand {
                UserId = userId, ProductId = productId, ChangeQuantityAction = action
            };
            commandHandler = new ChangeProductQuantityCommandHandler(basketRedisService.Object);

            basketDto = new UserBasketDto
            {
                Products = new List <BasketProduct> {
                    new BasketProduct {
                        Id = productId
                    }
                }
            };
        }
Exemplo n.º 3
0
        public async Task <IActionResult> ChangeProductQuantity(ChangeProductQuantityCommand command)
        {
            await mediator.Send(command);

            return(Ok());
        }
Exemplo n.º 4
0
 public Task HandleAsync(ChangeProductQuantityCommand command)
 {
     return(_writeRepository.UpdateQuantityAsync(command.Quantity, command.Id));
 }
Exemplo n.º 5
0
        public async Task <IActionResult> UpdateProductQuantityAsync([FromBody] ChangeProductQuantityCommand command)
        {
            await Mediator.SendAsync(command).ConfigureAwait(false);

            return(Ok());
        }