Пример #1
0
 public ToysOfPurchaseViewModel(PurchaseViewModel purchaseViewModel)
 {
     _purchaseViewModel = purchaseViewModel;
     _toyDAO            = new ToyDAO();
     SelectedToys       = new ObservableCollection <ToyModel>();
     UpdateAllToysList();
 }
        static void Main(string[] args)
        {
            using (var toyDAO = new ToyDAO())
            {
                var data = toyDAO.ReadAllChild().Result;
                //var result = data
                //    .Include(x => x.Product)
                //    .Include(x => x.Product.ProductForPetType)
                //    .Where(x => x.Product.Price >= 0
                //                && x.Product.Price <= 99999
                //                && x.Product.ProductForPetType.Any(y => y.PetType.Name == "Thỏ"));

                var result = data
                             .Include(x => x.Product)
                             .Include(x => x.Product.ProductForPetType);

                //foreach (var ele in data)
                //{
                //    Console.WriteLine(ele.Product.ProductForPetType.ToArray().Length);
                //}

                foreach (var ele in result)
                {
                    Console.WriteLine(ele.Product.Name);
                }

                Console.WriteLine("Hello World!");
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            UserDAO dao = new UserDAO();

            Console.WriteLine("Username or email: ");
            string Username = Console.ReadLine();

            Console.WriteLine("Password: "******"Login success");

                ToyDAO ToyDao = new ToyDAO();

                Console.WriteLine("Search toy: ");
                string     toyName = Console.ReadLine();
                List <Toy> list    = ToyDao.FindToys(toyName);

                //Console.WriteLine("Three Random Toys");
                //List<Toy> list = ToyDao.RandomToy();

                foreach (Toy t in list)
                {
                    Console.WriteLine(t.ToString());
                }

                Console.WriteLine("Comment: ");
                string cmt = Console.ReadLine();
            }
            else
            {
                Console.WriteLine("Login fail");
                try
                {
                    if (register())
                    {
                        Console.WriteLine("Register successfull!");
                    }
                    else
                    {
                        Console.WriteLine("Register fail");
                    }
                }
                catch (Exception e)
                {
                    if (e.Message.Contains("UNIQUE USERNAME"))
                    {
                        Console.WriteLine("Register fail! Username already taken!");
                    }
                    if (e.Message.Contains("UNIQUE EMAIL"))
                    {
                        Console.WriteLine("Register fail! Email already taken!");
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Not done yet
        /// </summary>
        /// <param name="Username"></param>
        /// <param name="OrderItems"></param>
        /// <returns></returns>
        public bool CreateOrder(string Username, Dictionary <Toy, int> ListItems)
        {
            //Get connection and PuzzleShopDB
            var db     = utils.DBConnect.getDB();
            var Orders = db.GetCollection <Orders>("Orders");

            string OrderDate = DateTime.Now.ToString();
            double Total     = 0;

            OrderItem[] OrderItems = Array.Empty <OrderItem>();

            //iterate through list Toy-Quantity of user's order
            foreach (KeyValuePair <Toy, int> entry in ListItems)
            {
                ToyDAO toyDao = new ToyDAO();

                //Check quantity if enough
                if (toyDao.GetQuantity(entry.Key._id) < entry.Value)
                {
                    throw new Exception("Quantity exceed!");
                }

                //calculate Total price
                Total += entry.Key.Price * entry.Value;

                //Create a Order item
                OrderItem i = new OrderItem
                {
                    Toy      = entry.Key,
                    Quantity = entry.Value
                };

                //Add more memory to array
                Array.Resize <OrderItem>(ref OrderItems, OrderItems.Length + 1);
                //Add Order item to Toy-Quantity list
                OrderItems[OrderItems.Length - 1] = i;
            }
            //Status = -1 means Pending order
            // 0 means Processing order
            // 1 means Completed order
            int Status = -1;

            try
            {
                Orders.InsertOne(new Orders
                {
                    OrderDate  = OrderDate,
                    Username   = Username,
                    OrderItems = OrderItems,
                    Total      = Total,
                    Status     = Status
                });
                return(true);
            }
            catch (Exception)
            {
                throw;
            }
        }
 public async Task <IActionResult> GetToy()
 {
     using (var toyDAO = new ToyDAO())
     {
         return(Json((await toyDAO.ReadAll(false))
                     .ToArray()));
     }
 }
 public async Task <IActionResult> GetToySearchResult(string keyword)
 {
     using (var toyDAO = new ToyDAO()){
         return(Json((toyDAO.Context.Toy
                      .Include(x => x.Product)
                      .Where(x => x.Product.Name.IndexOf(keyword, StringComparison.OrdinalIgnoreCase) != -1))
                     .ToArray()));
     }
 }
Пример #7
0
        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            string searchValue = txtSearch.Text;
            ToyDAO toyDAO      = new ToyDAO();

            List <Toy> list = toyDAO.FindToys(searchValue);

            tblToy.DataSource = list;
        }
Пример #8
0
        public void loadData()
        {
            ToyDAO     toyDao = new ToyDAO();
            List <Toy> list   = toyDao.AllToys();

            tblToy.DataSource = list;
            User   LoggedUser = frmLogin.AuthorizedUser;
            string welcome    = $"Welcome {LoggedUser.FirstName} {LoggedUser.LastName}";

            lbWelcome.Text = welcome;
        }
Пример #9
0
 public ToyViewModel()
 {
     _toyDAO = new ToyDAO();
     _toy    = new ToyModel();
     ClearView();
     UpdateList();
     if (Toy.Id == 0)
     {
         Toy.Active = true;
     }
 }
Пример #10
0
        private void btnToyType_Click(object sender, EventArgs e)
        {
            ToyDAO        toyDao   = new ToyDAO();
            List <string> listType = toyDao.GetAllToyType();

            Dictionary <string, long> Type = new Dictionary <string, long>();

            foreach (string s in listType)
            {
                long quantity = toyDao.GetQuantityOfAType(s);
                Type.Add(s, quantity);
                MessageBox.Show(s + ": " + quantity);
            }
        }
Пример #11
0
        private void btnRate_Click(object sender, EventArgs e)
        {
            string Name      = txtName.Text;
            string Email     = txtEmail.Text;
            string Title     = txtTitle.Text;
            string Content   = txtContent.Text;
            int    Rate      = int.Parse(txtRate.Text);
            Toy    reviewToy = frmDisplayToy.SelectedToy;

            ToyDAO dao = new ToyDAO();

            try
            {
                dao.ReviewAToy(reviewToy, Name, Email, Title, Content, Rate);

                MessageBox.Show("Thanks!");
                this.Close();
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #12
0
        static void Main(string[] args)
        {
            using (var toyDAO = new ToyDAO())
            {
                //var data = toyDAO.ReadAllChild().Result;
                //var result = data
                //    .Include(x => x.Product)
                //    .Include(x => x.Product.ProductForPetType)
                //    .Where(x => x.Product.Price >= 0
                //                && x.Product.Price <= 99999
                //                && x.Product.ProductForPetType.Any(y => y.PetType.Name == "Thỏ"));

                //var result = data
                //    .Include(x => x.Product)
                //    .Include(x => x.Product.ProductForPetType);

                //foreach (var ele in data)
                //{
                //    Console.WriteLine(ele.Product.ProductForPetType.ToArray().Length);
                //}

                //foreach (var ele in result)
                //{
                //    Console.WriteLine(ele.Product.Name);
                //}

                //var tmp = new CutieshopContext().Product
                //    .Include(x => x.ProductForPetType)
                //    .ThenInclude(x => x.PetType)
                //    .Include(x => x.Accessory)
                //    .Include(x => x.Cage)
                //    .Include(x => x.Food)
                //    .Include(x => x.Toy)
                //    .ToArray()
                //    .Where(x => ProductEqualTypeNotNull(x, typeof(Food)))
                //    .ToArray();

                //var msgs = (new CutieshopContext().Product
                //        .Include(x => x.ProductForPetType)
                //        .ThenInclude(x => x.PetType)
                //        .Include(x => x.Accessory)
                //        .Include(x => x.Cage)
                //        .Include(x => x.Food)
                //        .Include(x => x.Toy)
                //        .ToArray()
                //        .Where(x => ProductEqualTypeNotNull(x, typeof(Food))
                //                    && x.Price <= 300000
                //                    && x.Price >= 100000
                //                    && x.ProductForPetType.Any(y => y.PetType.Name == "Mèo"))
                //        .Select(x => new { x.Name, Price = x.Price.ToString(), x.ProductId, x.ImgUrl, BtnText = "Đặt liền" })
                //        .ToArray())
                //    .Select(ele => (ele.Name, ele.Price, ele.ProductId, ele.ImgUrl, ele.BtnText))
                //    .ToArray();

                //Console.WriteLine(msgs.Length);

                //Console.WriteLine("Hello World!");

                var arr = new[]
                {
                    new
                    {
                        arr = new[] { 1, 2, 3 }
                    },
                    new
                    {
                        arr = new[] { 1, 6 }
                    }
                };

                var tmp  = arr.SelectMany(x => x.arr).ToArray();
                var tmp2 = arr.Aggregate((a, b) => new { arr = a.arr.Concat(b.arr).ToArray() });
            }
        }