Exemplo n.º 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));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a user product.
        /// </summary>
        /// <param name="informations"></param>
        public void CreateUserProduct(List <string> informations)
        {
            UserProduct user_product = new UserProduct
            {
                Username  = informations[0],
                ProductId = Int32.Parse(informations[1]),
                IsActive  = Boolean.Parse(informations[2])
            };

            Console.WriteLine("Create User Product: " + ctr_userproduct.Create(user_product));
        }
 public string Create(UserProduct user_product)
 {
     return(user_product_ctr.Create(user_product));
 }