Exemplo n.º 1
0
        static void Main(string[] args)
        {
            IProductRepository productRepository = new FileProductRepository();
            var products = productRepository.GetAll();

            Console.WriteLine("Product Manager Project in C#\r");
            Menu();
            string inputValue = Console.ReadLine();

            while (inputValue != "q")
            {
                switch (inputValue)
                {
                case "1":
                    ShowAllProducts(products);
                    inputValue = Console.ReadLine();
                    break;

                case "2":
                    SearchProductMinPrice(products);
                    inputValue = Console.ReadLine();
                    break;

                case "3":
                    AddProductWithUsersParameters(products, productRepository);
                    inputValue = Console.ReadLine();
                    break;

                case "4":
                    DeleteProduct(products, productRepository);
                    inputValue = Console.ReadLine();
                    break;

                case "5":
                    SearchProductByName(products);
                    inputValue = Console.ReadLine();
                    break;

                case "6":
                    ShowProducersAndTheirProducts(products);
                    inputValue = Console.ReadLine();
                    break;

                case "7":
                    IShopsRepository shopsRepository = new ShopsRepository();
                    shopsRepository.ShowProductsInEachShop(products);
                    inputValue = Console.ReadLine();
                    break;

                case "q":
                    break;

                default:
                    Console.WriteLine("This option is not defined. Try again!");
                    inputValue = Console.ReadLine();
                    break;
                }
            }
        }
        public static void AddBooksToShop()
        {
            var shopRepo = new ShopsRepository();
            var shop     = shopRepo.FindBy(s => s.Address.StartsWith("Fantasigatan")).FirstOrDefault();
            var bookRepo = new BooksRepository();
            var books    = bookRepo.GetAll();
            var sbRepo   = new ShopBookRepository();

            foreach (var book in books)
            {
                sbRepo.Add(new ShopBook {
                    BookId = book.Id, ShopId = shop.Id
                });
            }
            sbRepo.Save();
        }
Exemplo n.º 3
0
 public void IniciarFactory()
 {
     _providerFactory = new ProviderFactory();
     _providerFactory.AddProvider(new MySqlProvider());
     _shopsRepository = new ShopsRepository(_providerFactory);
 }