private static Item GetItem() { Write("Podaj kod: "); string ean = ReadLine(); IItemsService itemsService = new FakeItemsService(); List <Item> items = itemsService.Search(ean); if (items.Any()) { foreach (Item item in items) { WriteLine($"{items.IndexOf(item) + 1} \t- {item}"); } Write("Podaj indeks"); if (int.TryParse(ReadLine(), out int index)) { return(items[index - 1]); } else { Write("Błędna wartość"); } } return(null); }
private static void GetItemsTest() { IItemsService itemsService = new FakeItemsService(); List <Item> items = itemsService.Get(); List <Product> products = items.OfType <Product>().ToList(); foreach (Item item in items) { Console.WriteLine(item); item.Print(); } foreach (Product product in products) { product.Print(); } }
private static void CreateOrderTest() { Console.WriteLine("Witaj w naszym sklepie!"); Console.WriteLine("Podaj id klienta:"); int customerId = int.Parse(Console.ReadLine()); Console.WriteLine("Podaj id produktu:"); int productId = int.Parse(Console.ReadLine()); Console.WriteLine("Podaj ilość:"); int quantity = int.Parse(Console.ReadLine()); // TODO: pobrac klienta i produkt ze zrodla danych ICustomersService customersService = new FakeCustomersService(); IItemsService itemsService = new FakeItemsService(); // Przygotowanie danych Generator.Generator generator = new Generator.Generator(); var customers = generator.GetCustomers(100); customersService.Add(customers); var products = generator.GetProducts(50); var services = generator.GetServices(50); // połączenie zbiorów var items = products.OfType <Item>().Concat(services).ToList(); itemsService.Add(items); // Pobranie Customer customer = customersService.Get(customerId); Item item = itemsService.Get(productId); Order order = new Order("ZA 001", customer); order.Details.Add(new OrderDetail(item, quantity)); }
static void Main(string[] args) { WriteLine("Hello World!"); // Install-Package Microsoft.Extensions.Configuration // Install-Package Microsoft.Extensions.Configuration.FileExtensions // Install-Package Microsoft.Extensions.Configuration.Json var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); WriteLine(configuration.GetConnectionString("ShopConnection")); // Install-Package Microsoft.Extensions.DependencyInjection ServiceCollection services = new ServiceCollection(); services.AddTransient <ICustomersService, DbCustomersService>(); services.AddTransient <IItemsService, DbItemsService>(); // Install-Package Microsoft.EntityFrameworkCore.SqlServer services.AddDbContext <ShopContext>(options => options .UseSqlServer(configuration.GetConnectionString("ShopConnection"))); ServiceProvider serviceProvider = services.BuildServiceProvider(); // ICustomersService customersService = new FakeCustomersService(); ICustomersService customersService = serviceProvider.GetService <ICustomersService>(); var query = customersService.Get(); var items = new FakeItemsService().Get(); IItemsService itemsService = serviceProvider.GetService <IItemsService>(); itemsService.AddRange(items); var customers = customersService.Search(new CustomerSearchCriteria { Country = "Poland" }); var newCustomers = new FakeCustomersService().Get(); foreach (var newCustomer in newCustomers) { customersService.Add(newCustomer); } LinqTest(customersService); // Uwaga: W przypadku float/double mimo dzielenia przez zero nie pojawi się błąd, // lecz przyjmie wartość infinity! double result = 2d / 0; Console.WriteLine(result); // DelegateTest(); // Typ anonimowy // AnonymouseTypeTest(); Customer customer = GetCustomer(); var order = new Order(customer); Item item; do { item = GetItem(); int quantity = GetQuantity(); OrderDetail detail = new OrderDetail(item, quantity); order.AddDetail(detail); } while (item != null); // EnumTest(order); // ExtensionsMethodTest(); GetCustomersTest(); // GetItemsTest(); #region Variable vs Reference Types VariableTest(); StringTest(); ReferenceTest(); #endregion Helper.GreaterThanZero(100); }