コード例 #1
0
        public static void AddToCart(int id, Customers c1, int q)
        {
            //addtocart called create new instance of orderedItem
            using (var ctx = new BrainsmithContext())
            {
                OrderedItems os  = new OrderedItems();
                var          res = ctx.Toys.Where(s => s.ToyID == id).Select(s => s.Price).ToList();
                var          ord = ctx.Orders.Where(c => c.CId == c1.CId).Select(c => c.OrderID);
                foreach (var item in ord)
                {
                    os.OrderID = item;
                }


                os.ToysID   = id;
                os.Quantity = q;
                os.Amount   = res.Sum() * q;
                ctx.OrderedItems.Add(os);
                ctx.SaveChanges();
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("\tBrainSmith Toys-Store  C#\r");
            Console.WriteLine("\t------------------------\n");
            Console.WriteLine("\tPlease Register Your Self");
            // Customers c1 = new Customers();
            // ShipAddresses s1 = new ShipAddresses();
            // using (var ctx = new BrainsmithContext())
            // {
            //     c1.AddCustomer();
            //     ctx.Customers.Add(c1);
            //     ctx.SaveChanges();
            //     s1.AddAddress(c1);
            //     ctx.ShipAddresses.Add(s1);
            //     ctx.SaveChanges();
            //     Orders o = new Orders();
            //     o.CId = c1.CId;
            //     ctx.Orders.Add(o);
            //     ctx.SaveChanges();
            // }

            while (true)
            {
                bool flag = false;
                Console.WriteLine("Choose an Option from the following list:");
                Console.WriteLine("\ta - AddAnother-ShipAddress");
                Console.WriteLine("\tv - View-All-the-Product");
                Console.WriteLine("\tb - Buy-Product");
                Console.WriteLine("\tc - CheckOut");
                Console.WriteLine("\ts - Search Prodcut by Category-Name");
                Console.WriteLine("\tE - Press E To Exit App");
                Console.Write("Your option? ");
                char choice = Convert.ToChar(Console.ReadLine());
                switch (choice)
                {
                case 'a':
                {
                    ShipAddresses sa = new ShipAddresses();
                    // sa.AddonotherAddress(c1);
                    var ctx = new BrainsmithContext();
                    ctx.ShipAddresses.Add(sa);
                    ctx.SaveChanges();
                    break;
                }

                case 'v':
                {
                    Allproducts();
                    break;
                }


                case 's':
                {
                    Console.WriteLine("Enter Category To search");
                    string Name = Console.ReadLine();
                    SearchProduct(Name);
                }

                    continue;

                case 'b':
                {
                    Allproducts();


                    var ctx = new BrainsmithContext();

                    Console.WriteLine("Enter toyId to purchase It!!!");
                    int id = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Enter Qunatity");
                    int q = Convert.ToInt32(Console.ReadLine());
                    //  AddToCart(id, c1, q);
                }
                    continue;

                case 'c':
                {
                    //   Checkout(c1);
                    //
                }
                    continue;

                case 'e':
                {
                    flag = true;
                }
                break;
                }
                if (flag == false)
                {
                    continue;
                }
                else
                {
                    break;
                }
            }
        }