Пример #1
0
        private static void SaveSalesmen(ShopDbContext db)
        {
            var salesmen = Console.ReadLine().Split(";");

            foreach (var salesman in salesmen)
            {
                db.Add(new Salesman {
                    Name = salesman
                });
            }
            db.SaveChanges();
        }
Пример #2
0
        private static void SaveReview(ShopDbContext db, string arguments)
        {
            var parts      = arguments.Split(';');
            var customerId = int.Parse(parts[0]);
            var itemId     = int.Parse(parts[1]);

            var review = new Review {
                CustomerId = customerId, ItemId = itemId
            };

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

            db.Add(new Customer
            {
                Name       = customerName,
                SalesmanId = salesmanId
            });

            db.SaveChanges();
        }
Пример #4
0
        private static void MakeOrder(ShopDbContext db, string arguments)
        {
            int[] commandArgs = arguments.Split(';').Select(int.Parse).ToArray();

            int   customerId = commandArgs[0];
            Order order      = new Order {
                CustomerId = customerId
            };

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

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

            db.Add(order);
            db.SaveChanges();
        }
Пример #5
0
        private static void SaveOrder(ShopDbContext 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 OrderItem
                {
                    ItemId = itemId
                });
            }

            db.Add(order);
            db.SaveChanges();
        }
Пример #6
0
        private static void SaveItems(ShopDbContext 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();
        }