Beispiel #1
0
 public void Add(PlacedOrderRows placedOrderRows)
 {
     using (var connection = new SqlConnection(this.connectionString))
     {
         connection.Execute("INSERT INTO PlacedOrderRows (OrderId, ProductId, Name, Price) VALUES(@orderId, @productId, @name, @price)", placedOrderRows);
     }
 }
        public int CreateOrderRowFromCart(int cartId)
        {
            if (cartId == 0)
            {
                return(0);
            }

            else
            {
                List <Cart> cartItems          = this.cartRepository.Get(cartId);
                int         orderIdForThisCart = this.GetRandomOrderId();

                foreach (var cartItem in cartItems)
                {
                    var productId   = cartItem.ProductId;
                    var productData = this.productRepository.Get(productId);

                    PlacedOrderRows tmpOrderRow = new PlacedOrderRows
                    {
                        OrderId   = orderIdForThisCart,
                        ProductId = productData.ProductId,
                        Name      = productData.Name,
                        Price     = productData.Price
                    };

                    this.placedOrderRowsRepository.Add(tmpOrderRow);
                }
                this.cartRepository.Delete(cartId);
                return(orderIdForThisCart);
            }
        }