示例#1
0
        public bool Add(long customerId)
        {
            var shoppingCart = _shoppingCartBusiness.GetActiveShoppingCart(customerId);

            if (shoppingCart == null)
            {
                throw new ArgumentException($"Carrinho não encontrado para o cliente: {customerId}.");
            }

            var listShoppingCartItem = _shoppingCartItemBusiness.GetShoppingCartItems(shoppingCart.Id, true);

            if (!listShoppingCartItem.Any())
            {
                throw new ArgumentException($"Carrinho de compras {shoppingCart.Id} está vazio.");
            }

            //var salesOder = _salesOrderBusiness.GetById()

            //Order
            SalesOrder salesOrder = new SalesOrder()
            {
                CustomerId     = shoppingCart.CustomerId,
                Id             = shoppingCart.Id,
                OrderStatus    = OrderStatus.WaitingPayment,
                UpdatedDate    = DateTime.Now,
                ShoppingCartId = shoppingCart.Id
            };

            //OrderItem
            foreach (var shoppingCartItem in listShoppingCartItem)
            {
                var validateQuantity = _productBusiness.GetStock((int)shoppingCartItem.ProductId);
                var price            = _productBusiness.GetUnitPrice((int)shoppingCartItem.ProductId);

                if (validateQuantity < shoppingCartItem.ProductQuantity)
                {
                    throw new ArgumentException($"Saldo insuficiente para o produto: {shoppingCartItem.ProductId}");
                }

                SalesOrderItem salesOrderItem = new SalesOrderItem()
                {
                    SalesOrderId    = salesOrder.Id,
                    ProductId       = shoppingCartItem.ProductId,
                    ProductQuantity = shoppingCartItem.ProductQuantity,
                    UnitPrice       = price
                };

                salesOrder.ListSalesOrderItem.Add(salesOrderItem);
            }

            return(_salesOrderBusiness.Add(salesOrder));
        }
示例#2
0
 public ShoppingCart GetActiveShoppingCart(long customerId)
 {
     return(_shoppingCartBusiness.GetActiveShoppingCart(customerId));
 }