コード例 #1
0
 /// <summary>
 /// Get OrderItem by ID
 /// </summary>
 /// <param name="OrderItemID">OrderItem ID</param>
 /// <returns></returns>
 public Task <OrderItem> GetOrderItemAsync(int OrderItemID)
 {
     return(Task.Run(() =>
     {
         return OrderItem.ExecuteCreate(OrderItemID);
     }));
 }
コード例 #2
0
        /// <summary>
        /// Delete an OrderItem
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public Task <bool> DeleteOrderItemAsync(int ID)
        {
            return(Task.Run(async() =>
            {
                OrderItem orderItem = OrderItem.ExecuteCreate(ID);
                orderItem.Delete();

                await UpdateTotalOfOrder(orderItem.OrderID);

                orderItem = OrderItem.ExecuteCreate(ID);

                return (orderItem == null) ? true : false;
            }));
        }
コード例 #3
0
        public ActionResult ShoppingCartView(string name)
        {
            if (name != null)
            {
                ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject();

                cart.TotalPrice = cart.TotalPrice - cart.ProductsList[name].Price;
                cart.ProductsList.Remove(name);

                return(View(cart));
            }
            else
            {
                //Save shopping cart code
                ShoppingCartModels cart = ShoppingCartModels.GetInstanceOfObject();
                int          accountID  = Int32.Parse(Session["CurrentID"].ToString());
                Order        order      = Order.ExecuteCreate(accountID, 1, 1, cart.TotalPrice);
                decimal      subtotal   = 0;
                bool         isPresent  = false;
                List <Order> orderList  = Order.ListByAccountID(accountID);

                order.Insert();

                foreach (Order o in orderList)
                {
                    List <OrderItem> orderItemList = OrderItem.ListByOrderID(o.ID);

                    foreach (OrderItem item in orderItemList)
                    {
                        item.Delete();
                    }
                }

                foreach (string key in cart.ProductsList.Keys)
                {
                    Product product = cart.ProductsList[key];
                    subtotal = subtotal + product.Price;
                    OrderItem orderItem = OrderItem.ExecuteCreate(order.ID, product.ID, 1, product.Price, subtotal);

                    if (!isPresent)
                    {
                        orderItem.Insert();
                    }
                }
                return(View(cart));
            }
        }
コード例 #4
0
        /// <summary>
        /// Create an OrderItem
        /// </summary>
        /// <param name="OrderID"></param>
        /// <param name="ProductID"></param>
        /// <param name="Quantity"></param>
        /// <param name="UnitCost"></param>
        /// <param name="Subtotal"></param>
        /// <returns></returns>
        public Task <bool> CreateOrderItemAsync(
            int OrderID,
            int ProductID,
            int Quantity,
            decimal UnitCost,
            decimal Subtotal)
        {
            return(Task.Run(async() =>
            {
                bool result = false;
                OrderItem orderItem = OrderItem.ExecuteCreate(OrderID, ProductID, Quantity, UnitCost, Subtotal);
                orderItem.Insert();

                await UpdateTotalOfOrder(orderItem.OrderID);

                result = true;
                return result;
            }));
        }
コード例 #5
0
        /// <summary>
        /// Update an Existing OrderItem
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="Quantity"></param>
        /// <param name="UnitCost"></param>
        /// <param name="Subtotal"></param>
        /// <returns></returns>
        public Task <bool> UpdateOrderItemAsync(
            int ID,
            int Quantity,
            decimal UnitCost,
            decimal Subtotal)
        {
            return(Task.Run(async() =>
            {
                bool result = false;
                OrderItem orderItem = OrderItem.ExecuteCreate(ID);

                if (orderItem != null)
                {
                    orderItem.Update(Quantity, UnitCost, Subtotal);

                    result = true;

                    await UpdateTotalOfOrder(orderItem.OrderID);
                }

                return result;
            }));
        }