示例#1
0
        public bool Addshoppingcart()
        {
            OrderBL obl1       = new OrderBL();
            var     listorders = obl1.GetAllOrderByIDUser(id);
            Orders  order      = new Orders();

            order.user      = new User();
            order.shoesList = new List <Shoes>();
            int b = listorders.FindIndex(x => x.Order_status == 0);

            if (b != -1)
            {
                var shoes     = sbl.GetShoesById(sh_id);
                int amount    = 0;
                int amountshp = 0;
                foreach (var or in listorders)
                {
                    if (or.Order_status == 0)
                    {
                        var detail2 = obl1.GetOrderDetailsByID(or.Order_id);
                        foreach (var shoess in detail2.shoesList)
                        {
                            if (shoess.Shoes_id == sh_id)
                            {
                                amountshp = shoess.Amount;
                            }
                        }
                    }
                }
                while (true)
                {
                    Console.Write("Input amount : ");
                    try{
                        amount = Convert.ToInt32(Console.ReadLine());
                        if ((amount > shoes.Amount && shoes.Amount - amountshp == 0) || (amount == shoes.Amount - amountshp && shoes.Amount - amountshp == 0))
                        {
                            Console.WriteLine("Quantity no longer please put another product .. !");
                            Console.ReadLine();
                            break;
                        }
                        else if (amount < 0)
                        {
                            throw new valueexception("Please enter a valid ,");
                        }
                        else if (amount > shoes.Amount - amountshp)
                        {
                            throw new valueexception("Not enough quantity , please re-enter ,");
                        }
                        else if (0 < amount && amount < shoes.Amount - amountshp)
                        {
                            break;
                        }
                    }
                    catch (valueexception e)
                    {
                        Console.Write(e.Message);
                        continue;
                    }catch {
                        Console.Write("Please enter a valid  ,");
                        continue;
                    }
                }
                int dem = 0;
                foreach (var or in listorders)
                {
                    if (or.Order_status == 0)
                    {
                        var detail = obl1.GetOrderDetailsByID(or.Order_id);
                        foreach (var shoess in detail.shoesList)
                        {
                            if (shoess.Shoes_id == sh_id)
                            {
                                obl1.updateAmount(amount, shoess.Shoes_id);
                                dem = 1;
                            }
                            else if (shoes.Shoes_id != sh_id)
                            {
                                dem = 0;
                            }
                        }
                    }
                }
                if (dem == 0)
                {
                    Console.WriteLine("Add in shopping cart: " + (obl1.InsertShoppingCarrt(listorders[b].Order_id, sh_id, amount, shoes.Price, 0) ? "completed!" : "not complete!"));
                    Console.ReadLine();
                    Displaylistshoes();
                }
                Console.WriteLine("Add in shopping cart completed !");
                Console.ReadLine();
                Displaylistshoes();
            }
            else if (b == -1)
            {
                order.user.User_id = id;
                order.Order_status = 0;
                order.shoesList.Add(sbl.GetShoesById(sh_id));
                var shoes = sbl.GetShoesById(sh_id);
                int amount;
                while (true)
                {
                    Console.Write("Input amount : ");
                    try{
                        amount = Convert.ToInt32(Console.ReadLine());
                        if ((amount > shoes.Amount && shoes.Amount == 0) || (amount == shoes.Amount && shoes.Amount == 0))
                        {
                            Console.WriteLine("Quantity no longer please put another product .. !");
                            Console.ReadLine();
                            break;
                        }
                        else if (amount < 0)
                        {
                            throw new valueexception("Please enter a valid,");
                        }
                        else if (amount > shoes.Amount)
                        {
                            throw new valueexception("Not enough quantity , please re-enter,");
                        }
                        else if (0 < amount && amount < shoes.Amount)
                        {
                            break;
                        }
                    }
                    catch (valueexception e)
                    {
                        Console.Write(e.Message);
                        continue;
                    }catch {
                        Console.Write("Please enter a valid  :");
                        continue;
                    }
                }
                order.shoesList[0].Amount = amount;
                var userdt = ubl.GetUserByid(id);
                order.Address = userdt.Address;
                order.phone   = userdt.Phone;
                Console.WriteLine("Add in shopping cart: " + (obl1.AddShppingCart(order) ? "completed!" : "not complete!"));
                Console.ReadLine();
                Displaylistshoes();
            }
            return(true);
        }