public async Task <IActionResult> Post(AddProductToCartCommand command) { await _dispatcher.SendAsync(command.Bind(c => c.CustomerId, UserId)); return(CreatedAtAction(nameof(Get), new GetCartQuery() { Id = command.CustomerId }, null)); }
public async Task <IActionResult> Post(Guid userId, [FromBody] AddProductToCartDTO dto) { var command = new AddProductToCartCommand(userId, dto.ProductId); var result = await CartSystem.AddProductToCart(command); if (result.IsSuccessful) { return(Ok()); } ; return(BadRequest(result.Message)); }
public async Task HandleAsync(FillCartCommand command) { foreach (var product in command.CartItems) { var addProductToCart = new AddProductToCartCommand( command.CustomerId, product.ProductId, product.Quantity ); await _dispatcher.SendAsync(addProductToCart); } }
public async Task <CommandResult> AddProductToCart(AddProductToCartCommand command) { return(await _commandActor.Ask <CommandResult>(command)); }
public async Task <IActionResult> PostAsync(AddProductToCartCommand command) { var result = await SendAsync(command.Bind(c => c.CustomerId, UserId), resourceId : command.CustomerId, resource : "carts"); return(result); }
static async Task Main(string[] args) { // create and configure the service container IServiceCollection serviceCollection = ConfigureServices(); // build the service provider IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider(); IUnitOfWork uow = serviceProvider.GetService <IUnitOfWork>(); // get all users var users = await uow.GetUserRepository().GetAllAsync(); PrintUsers(users); // get all products var prods = await uow.GetProductRepository().GetAllAsync(); PrintProducts(prods); Command cmd; Command saveCommand = new SaveCommand(uow); // create carts for users[0] & users[1] cmd = new CreateCartCommand(users[0]); cmd.Execute(); cmd = new CreateCartCommand(users[1]); cmd.Execute(); var cart1 = users[0].Carts.Last(); var cart2 = users[1].Carts.Last(); saveCommand.Execute(); // some operation on npaul's cart cmd = new AddProductToCartCommand(cart1, prods[0], 5); cmd.Execute(); cmd = new AddProductToCartCommand(cart1, prods[1], 3); cmd.Execute(); cmd = new UpdateCartItemQuantityCommand(cart1, prods[0], 6); cmd.Execute(); saveCommand.Execute(); PrintCart(cart1); // some operation on jdoe's cart cmd = new AddProductToCartCommand(cart2, prods[0], 1); cmd.Execute(); cmd = new AddProductToCartCommand(cart2, prods[1], 3); cmd.Execute(); cmd = new AddProductToCartCommand(cart2, prods[2], 2); cmd.Execute(); cmd = new AddProductToCartCommand(cart2, prods[3], 2); cmd.Execute(); saveCommand.Execute(); PrintCart(cart2); cmd = new UpdateProductPriceCommand(prods[1], 15); cmd.Execute(); saveCommand.Execute(); PrintCart(cart1); PrintCart(cart2); // cleaning cmd = new DeleteCartCommand(cart1, uow.GetCartRepository()); cmd.Execute(); cmd = new DeleteCartCommand(cart2, uow.GetCartRepository()); cmd.Execute(); saveCommand.Execute(); cmd = new UpdateProductPriceCommand(prods[1], 17.50); cmd.Execute(); saveCommand.Execute(); }
public HttpResponseMessage PutCartCommand(AddProductToCartCommand command) { bus.Send(command); return this.Request.CreateResponse(HttpStatusCode.OK); }