public void Handle(AddProductToCart command)
        {
            var product = _architectureContext.Products.Find(command.ProductId);

            var order = _architectureContext.Orders
                        //.Include(x => x.OrderItems).ThenInclude(c => c.Product)
                        .FirstOrDefault(/*x => x.Customer.Id == _user.UserId() && x.Closed == false*/);

            if (order == null)
            {
                var customer = _architectureContext.Customers.Find(command.UserId);

                order = new Domain.Models.Order(customer);
                var orderItem = new OrderItem(product);
                order.OrderItems.Add(orderItem);
                Db().Add(order);
                Commit(new ProductAddedToCart(order.Id, orderItem.Id, command.ProductId));
            }
            else
            {
                var orderItem = order.OrderItems.FirstOrDefault(x => x.Product.Id == command.ProductId);
                order.AddOrUpdateItem(orderItem, product);

                //Db().Update(order);
                Commit(new ProductAddedToCart(order.Id, order.Id, command.ProductId));
            }
        }
        public void Handle(AddProductToCart message)
        {
            var cart = _repository.Load <ShoppingCart>(message.CartId);

            cart.AddProduct(message.ProductId);

            _repository.SaveChanges(cart);
        }
Beispiel #3
0
        public void AddProduct([FromBody] AddProductToCart value)
        {
            var allProduct = ProductController.Products;
            var qry        = allProduct.FirstOrDefault(it => it.Id == value.ProductId);

            if (qry == null)
            {
                return;
            }
            Cart.ProductIds.Add(value.ProductId);
            Cart.TotalPrice += qry.Price;
        }
        public async Task <IActionResult> AddProductToCart([FromBody] ModifyCartProductDto dto)
        {
            try
            {
                var addProduct = new AddProductToCart(dto.CartId, dto.ProductId, 1);
                await _mediator.Send(addProduct);

                return(Ok(new { message = "Product added to cart" }));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            DatabaseInterface db = new DatabaseInterface("BANGAZONCLI_DB");

            db.CheckDatabaseTable("Customer", DbTables.Customer);
            db.CheckDatabaseTable("Product", DbTables.Product);
            db.CheckDatabaseTable("PaymentType", DbTables.PaymentType);
            db.CheckDatabaseTable("[Order]", DbTables.Order);
            db.CheckDatabaseTable("OrderProduct", DbTables.OrderProduct);
            DbInitializer.Initialize(db);

            MainMenu        menu            = new MainMenu();
            CustomerManager customerManager = new CustomerManager(db);
            OrderManager    orderManager    = new OrderManager(db);

            // Choice will hold the number entered by the user
            // after main menu ws displayed
            int choice;

            do
            {
                // Show the main menu
                choice = menu.Show();

                switch (choice)
                {
                case 1:
                    AddCustomer.DoAction(customerManager);
                    break;

                case 2:
                    ChooseActiveCustomer.DoAction(customerManager);
                    break;

                case 3:
                    AddPaymentType.DoAction(customerManager);
                    break;

                case 5:
                    AddProductToCart.DoAction(orderManager);
                    break;

                case 6:
                    CloseOrder.DoAction(orderManager);
                    break;
                }
            } while (choice != 7);
        }
Beispiel #6
0
        public async Task <ActionResult <UserManagerResponse> > addToUserCart([FromBody] AddProductToCart product)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (User != null)
            {
                int AvailableQuantity = _ProductRepo.getProductQuantity(product.ProductId);
                if (AvailableQuantity >= product.InCartQuantity)
                {
                    var cartItem = _mapper.Map <CartItem>(product);
                    var info     = _ProductRepo.getProductById(cartItem.ProductId);
                    cartItem.UserId     = userId;
                    cartItem.ItemName   = info.Name;
                    cartItem.Image      = info.ImagePathsArr[0];
                    cartItem.UnitePrice = info.Price;
                    var result = _CartRepo.AddToCartQuantity(cartItem, AvailableQuantity);
                    if (!result.IsSuccessful)
                    {
                        await _CartRepo.addToUserCart(cartItem);

                        _CartRepo.saveContext();
                        return(new UserManagerResponse
                        {
                            IsSuccessful = true,
                            Message = "Added to cart"
                        });
                    }
                    _CartRepo.saveContext();
                    return(result);
                }
                return(new UserManagerResponse
                {
                    IsSuccessful = false,
                    Message = "Desired Quantity is over the available"
                });
            }
            return(new UserManagerResponse
            {
                IsSuccessful = false,
                Message = "Process not successful"
            });
        }
Beispiel #7
0
 public void Handle(AddProductToCart cmd)
 {
     Execute(cmd.CartId, (cart) => cart.AddProduct(cmd.ProductId, cmd.Price));
 }
 public IEvent Handle(AddProductToCart command)
 {
     throw new System.NotImplementedException();
 }
 public async Task <IActionResult> Post(AddProductToCart command)
 => await SendAsync(command.Bind(c => c.CustomerId, UserId));
 public async Task HandleAsync(AddProductToCart command)
 {
     await ExecuteAsync(command.CartId, cart => cart.AddProduct(command.ProductId, command.Price));
 }
Beispiel #11
0
 public async Task <IActionResult> Post([FromBody] AddProductToCart command)
 => await PublishAsync(command.Bind(c => c.CustomerId, UserId));