private static void SaveItems(ShopDbContext db) { while (true) { string[] line = Console.ReadLine().Split(';'); if (line[0] == "END") { break; } Item item = new Item { Name = line[0], Price = decimal.Parse(line[1]) }; db.Items.Add(item); db.SaveChanges(); } }
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(); }
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(); }
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(); }