Ejemplo 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));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validates a given password.
        /// </summary>
        /// <param name="user"></param>
        /// <returns>bool</returns>
        public bool ValidatePassword(CustomUser user)
        {
            CustomUserController ctrl = new CustomUserController();

            CustomUser storedUser = ctrl.FindByUsername(user.Username);

            string storedHash = storedUser.Password;

            if (user.Password == storedHash && storedUser.IsActive == true)
            {
                return(true);
            }

            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
 public CustomUser GetCustomUser(string name)
 {
     return(ctrl.FindByUsername(name));
 }