Esempio 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
                    }
                }
            };
        }
        public async Task <IActionResult> ChangeProductQuantity(ChangeProductQuantityCommand command)
        {
            await mediator.Send(command);

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

            return(Ok());
        }