private static void SaveOrder(MyDbContext db, string arguments)
        {
            var parts      = arguments.Split(';');
            var customerId = int.Parse(parts[0]);

            var order = new Order
            {
                CustomerId = customerId
            };

            for (int i = 1; i < parts.Length; i++)
            {
                var itemId = int.Parse(parts[i]);


                order.Items.Add(new ItemOrder
                {
                    ItemId = itemId
                });
            }



            db.Add(order);
            db.SaveChanges();
        }
Пример #2
0
        private static void RegisterCustomer(MyDbContext db, string argument)
        {
            var parts        = argument.Split(';');
            var customerName = parts[0];
            var salesmanId   = int.Parse(parts[1]);

            db.Add(new Customer
            {
                Name       = customerName,
                SalesmanId = salesmanId
            });
            db.SaveChanges();
        }
        private static void SaveSalesman(MyDbContext db)
        {
            var salesmans = Console.ReadLine().Split(';', StringSplitOptions.RemoveEmptyEntries);

            foreach (var salesman in salesmans)
            {
                db.Add(new Salesman {
                    Name = salesman
                });
            }

            db.SaveChanges();
        }
        private static void RegisterCustomer(MyDbContext db, string argumentStrings)
        {
            var arguments = argumentStrings.Split(';');
            var name      = arguments[0];
            var id        = int.Parse(arguments[1]);

            db.Add(new Customer
            {
                Name       = name,
                SalesmanId = id
            });
            db.SaveChanges();
        }
        private static void SaveReview(MyDbContext db, string arguments)
        {
            var parts      = arguments.Split(';');
            var customerId = int.Parse(parts[0]);
            var itemId     = int.Parse(parts[1]);

            db.Add(new Review
            {
                CustomerId = customerId,
                ItemId     = itemId
            });
            db.SaveChanges();
        }
        private static void SaveItems(MyDbContext db)
        {
            while (true)
            {
                var line = Console.ReadLine();

                if (line == "END")
                {
                    break;
                }

                var parts     = line.Split(';');
                var itemName  = parts[0];
                var itemPrice = decimal.Parse(parts[1]);

                db.Add(new Item
                {
                    Name  = itemName,
                    Price = itemPrice
                });
            }
            db.SaveChanges();
        }