/// <summary> /// Adds a new item to a existing cart /// </summary> /// <remarks>If the item alredy exists in the cart, then only its quantity /// is updated</remarks> public void AddToCart(CartDS.CartItemsDataTable cartItems, int productId, int quantity) { try { ProductBusinessObject productBO = new ProductBusinessObject(); ProductDS products = new ProductDS(); productBO.GetProductById(products, productId); if (cartItems.Rows.Count > 0) { DataRow[] selectedItems = cartItems.Select("productID=" + productId); if (selectedItems.Length > 0) { ((CartDS.CartItem)selectedItems[0]).Quantity += quantity; } else { cartItems.AddCartItem(quantity, productId, products.Products[0].ModelName, products.Products[0].UnitCost); } } else { cartItems.AddCartItem(quantity, productId, products.Products[0].ModelName, products.Products[0].UnitCost); } } catch (Exception e) { throw new ApplicationException(ResourceManager.GetString("RES_ExceptionCantAddCartItem"), e); } }
/// <summary> /// Creates a new order with the specified params /// </summary> public int CreateOrderFromCart(int customerId, CartDS.CartItemsDataTable items) { OrderDALC orderDALC = new OrderDALC(); ProductDALC productDALC = new ProductDALC(); int orderId = orderDALC.CreateOrder(customerId, DateTime.Now, DateTime.Now.AddDays(2)); foreach (CartDS.CartItem item in items) { ProductDS productDS = new ProductDS(); productDALC.GetProductById(productDS, item.ProductId); orderDALC.CreateOrderItem(orderId, item.ProductId, productDS.Products[0].UnitCost, item.Quantity); } return(orderId); }