示例#1
0
        /// <summary>
        /// Ships all orders connected to a given user that isn't shipped.
        /// </summary>
        /// <param name="username"></param>
        public void ShipOrders(string username)
        {
            int   index;
            Order order;
            List <OrderDetail> order_details;
            List <Order>       orders;

            //Find orders connected to the given username
            orders = ctr_order.FindByUsername(username);

            index = 0;
            //sort all orders from the list that already is shipped
            while (index < orders.Count)
            {
                order = orders[index];

                if (order.IsShipped)
                {
                    orders.Remove(order);
                }

                else
                {
                    index++;
                }
            }

            //ships the unshipped orders to the user.
            foreach (Order current_order in orders)
            {
                OrderDetail temp_od = new OrderDetail
                {
                    OrderId = current_order.Id
                };

                order_details = ctr_orderdetail.Find(temp_od, "Order Id");

                foreach (OrderDetail order_detail in order_details)
                {
                    UserProduct user_product = new UserProduct
                    {
                        Username  = username,
                        ProductId = order_detail.ProductId,
                        IsActive  = false
                    };

                    Console.WriteLine("Create User Product: " + ctr_userproduct.Create(user_product));
                }

                //mark the order as shipped.
                current_order.IsShipped = true;
                Console.WriteLine("Update Order: " + ctr_order.Update(current_order));

                //Updates the wallet of the user.
                CustomUser user = ctr_user.FindByUsername(current_order.Username);
                user.Wallet -= current_order.Price;
                Console.WriteLine("Update User wallet: " + ctr_user.Update(user));
            }
        }
示例#2
0
        /// <summary>
        /// Updates a user
        /// </summary>
        /// <param name="informations"></param>
        public void UpdateUser(List <string> informations)
        {
            CustomUser user = new CustomUser
            {
                Username = informations[0],
                Password = informations[1],
                Email    = informations[2],
                Wallet   = Double.Parse(informations[3])
            };

            Console.WriteLine("Update User: " + ctr_user.Update(user));
        }