Exemplo n.º 1
0
        static void CheckBug()
        {
            List <IProduct> books = new List <IProduct>();

            PaperBook TolkienPaperBook1 = new PaperBook("Silmarillion", "Tolkien", 500);

            books.Add(TolkienPaperBook1);

            PaperBook TolkienPaperBook2 = new PaperBook("Hobbit", "Tolkien", 300);

            books.Add(TolkienPaperBook2);

            PaperBook ZelaznyPaperBook1 = new PaperBook("Nine Princes in Amber", "Zelazny", 400);

            books.Add(ZelaznyPaperBook1);

            DeliveryCalculator calculator   = new DeliveryCalculator();
            ActionProvider     provider     = new ActionProvider();
            ShoppingCart       cart         = new ShoppingCart(calculator, provider);
            List <IPromo>      listOfPromos = new List <IPromo> {
            };
            IPromo promo1 = new PercentDiscountPromo(20);

            listOfPromos.Add(promo1);
            IPromo promo2 = new FreeBookPromo(ZelaznyPaperBook1);

            listOfPromos.Add(promo2);
            decimal finalPrice = cart.GetTotalPrice(books, listOfPromos);

            Console.WriteLine(finalPrice);
        }
Exemplo n.º 2
0
        public static void Show()
        {
            IBookAdapter paperBook = new PaperBook {
                Contenido = "Soy un libro físico"
            };

            paperBook.Compone();
            paperBook.Imprime();
            paperBook.Enviar();

            IBookAdapter mediaBook = new PdfBook {
                Contenido = "Soy un libro digital"
            };

            mediaBook.Compone();
            mediaBook.Imprime();
            mediaBook.Enviar();
        }
Exemplo n.º 3
0
        static void PercentDiscount()
        {
            List <IProduct> books = new List <IProduct>();

            PaperBook TolkienPaperBook1 = new PaperBook("Silmarillion", "Tolkien", 500);

            books.Add(TolkienPaperBook1);

            PaperBook TolkienPaperBook2 = new PaperBook("Hobbit", "Tolkien", 300);

            books.Add(TolkienPaperBook2);

            DeliveryCalculator calculator   = new DeliveryCalculator();
            ActionProvider     provider     = new ActionProvider();
            ShoppingCart       cart         = new ShoppingCart(calculator, provider);
            IPromo             promo        = new PercentDiscountPromo(20);
            List <IPromo>      listOfPromos = new List <IPromo> {
                promo
            };
            decimal finalPrice = cart.GetTotalPrice(books, listOfPromos);

            Console.WriteLine(finalPrice);
        }
Exemplo n.º 4
0
        static void FreeEBookAction()
        {
            List <IProduct> books = new List <IProduct>();

            PaperBook TolkienPaperBook1 = new PaperBook("Silmarillion", "Tolkien", 500);

            books.Add(TolkienPaperBook1);

            PaperBook TolkienPaperBook2 = new PaperBook("Hobbit", "Tolkien", 300);

            books.Add(TolkienPaperBook2);

            EBook TolkienEBook1 = new EBook("Fellowship of the ring", "Tolkien", 300);

            books.Add(TolkienEBook1);

            DeliveryCalculator calculator   = new DeliveryCalculator();
            ActionProvider     provider     = new ActionProvider();
            ShoppingCart       cart         = new ShoppingCart(calculator, provider);
            List <IPromo>      listOfPromos = new List <IPromo>();
            decimal            finalPrice   = cart.GetTotalPrice(books, listOfPromos);

            Console.WriteLine(finalPrice);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            User      user1 = new User("Customer", 22, 5000, 0);
            EBook     book1 = new EBook("Harry Potter 1", "J.K. Rowling", 499, Format.PDF);
            PaperBook book2 = new PaperBook("Harry Potter 2", "J.K. Rowling", 499);

            EBook     book11 = new EBook("Harry Potter 1", "J.K. Rowling", 499, Format.PDF);
            PaperBook book22 = new PaperBook("Harry Potter 2", "J.K. Rowling", 499);

            EBook     book3  = new EBook("Harry Potter 3", "J.K. Rowling", 499, Format.epub);
            PaperBook book33 = new PaperBook("Harry Potter 3", "J.K. Rowling", 499);

            EBook     book4  = new EBook("Harry Potter 4", "J.K. Rowling", 499, Format.epub);
            PaperBook book44 = new PaperBook("Harry Potter 4", "J.K. Rowling", 499);

            PaperBook book5 = new PaperBook("Harry Potter 5", "J.K. Rowling", 499);

            EBook book6 = new EBook("Harry Potter 7", "J.K. Rowling", 499, Format.PDF);

            BookRange bookRange = new BookRange();

            bookRange.AddBooks(
                book1, book2, book11, book22, book3, book33,
                book4, book44, book5, book6);

            // Создание корзины
            Cart cart = new Cart(bookRange);

            // Добавление промокодов и акций
            cart.AddBonus(PromoFactory.createPromo(IPromocode.PromoType.FreeBookPromo));
            cart.AddBonus(PromoFactory.createPromo(IPromocode.PromoType.FreeDeliveryPromo));
            cart.AddBonus(PromoFactory.createPromo(IPromocode.PromoType.MoneyPromo));
            cart.AddBonus(PromoFactory.createPromo(IPromocode.PromoType.PercentagePromo));
            cart.AddBonus(SaleFactory.createPromo(ISale.SaleType.OnePlusOneEqThreeSale));

            while (true)
            {
                // Стартовое меню
                Console.Clear();
                List <BookCard> bookList = bookRange.prepareBookCardList();
                bookList.Sort((x, y) => x.Book.Title.CompareTo(y.Book.Title));
                PrintStartInfo(user1, bookRange, cart, bookList);
                int option = readKey();

                if (option == 0) // Корзина
                {
                    Console.Clear();
                    cart.calculateCost();
                    List <BookCard> bookCards   = cart.GetAllBooksInCart();
                    bool            isCartEmpty = bookCards.Count == 0;
                    if (isCartEmpty)
                    {
                        Console.WriteLine("Корзина пуста");
                    }

                    while (!isCartEmpty)
                    {
                        Console.Clear();
                        bookCards = cart.GetAllBooksInCart();
                        cart.calculateCost();
                        PrintCartInfo(bookCards, cart.getBonuses(true), cart.GetPriceSum());
                        option = readKey();
                        switch (option)
                        {
                        case 0:
                        {
                            Console.WriteLine();
                            Console.WriteLine("Выход в главное меню");
                            isCartEmpty = true;
                            break;
                        }

                        case 1:
                        {
                            // Оплата товаров
                            double price = cart.GetPriceSum();
                            if (price < user1.Balance)
                            {
                                PrintPaymentInfo(user1, bookCards, price);
                                cart.MakePurchase(user1);
                            }
                            else
                            {
                                Console.WriteLine("У вас недостаточно средств");
                            }
                            isCartEmpty = true;
                            break;
                        }

                        case 2:
                        {
                            // Активация бонусов
                            List <IBenefit> bonuses = cart.getBonuses(false);
                            PrintBonusSelectionInfo(bonuses);
                            while (true)
                            {
                                option = readKey();
                                //bonuses.Sort((x, y) => x.CompareTo(y));
                                if (option == 0)
                                {
                                    break;
                                }
                                else if (option > 0 && option <= bonuses.Count)
                                {
                                    bonuses[option - 1].Apply(cart, bookRange);
                                    Console.WriteLine("Бонус активирован");
                                    break;
                                }
                                else
                                {
                                    Console.WriteLine("Такого бонуса не существует");
                                }
                            }
                            break;
                        }

                        case 8:
                        {
                            // Очистка бонусов
                            cart.clearBonus();
                            Console.WriteLine();
                            Console.WriteLine("Бонусы очищены");
                            break;
                        }

                        case 9:
                        {
                            // Очистка корзины
                            cart.Clear();
                            Console.WriteLine();
                            Console.WriteLine("Корзина очищена");
                            isCartEmpty = true;
                            break;
                        }

                        default:
                            continue;
                        }
                    }
                }
                else if (option > 0 && option <= bookRange.getBooksCount())
                {
                    cart.AddToCart(bookList[option - 1]);
                    Console.WriteLine("Товар добавлен в корзину");
                }
                else
                {
                    Console.WriteLine("Такого товара не существует");
                }

                Console.WriteLine("Нажмите Enter для продолжения.");
                while (Console.ReadKey().Key != ConsoleKey.Enter)
                {
                }
                Console.Clear();
            }
        }
Exemplo n.º 6
0
        static List <IProduct> Library()
        {
            //-------------------------------------------------------------------------------------------
            //Создаем набор книг
            List <IProduct> books = new List <IProduct> ();
            //-------------------------------------------------------------------------------------------
            //Автор - Tolkien
            //Бумажные
            PaperBook TolkienPaperBook1 = new PaperBook("Silmarillion", "Tolkien", 500);

            books.Add(TolkienPaperBook1);
            PaperBook TolkienPaperBook2 = new PaperBook("Hobbit", "Tolkien", 300);

            books.Add(TolkienPaperBook2);
            //Электронные
            EBook TolkienEBook1 = new EBook("Fellowship of the ring", "Tolkien", 300);

            books.Add(TolkienEBook1);
            EBook TolkienEBook2 = new EBook("Two towers", "Tolkien", 300);

            books.Add(TolkienEBook2);
            EBook TolkienEBook3 = new EBook("The Return of the king", "Tolkien", 300);

            books.Add(TolkienEBook3);
            //-------------------------------------------------------------------------------------------
            //Автор - Zelazny
            //Бумажные
            PaperBook ZelaznyPaperBook1 = new PaperBook("Nine Princes in Amber", "Zelazny", 400);

            books.Add(ZelaznyPaperBook1);
            PaperBook ZelaznyPaperBook2 = new PaperBook("The Guns of Avalon", "Zelazny", 500);

            books.Add(ZelaznyPaperBook2);
            PaperBook ZelaznyPaperBook3 = new PaperBook("Sign of the Unicorn", "Zelazny", 700);

            books.Add(ZelaznyPaperBook3);
            //Электронные
            EBook ZelaznyEBook1 = new EBook("The Hand of Oberon", "Zelazny", 400);

            books.Add(ZelaznyEBook1);
            EBook ZelaznyEBook2 = new EBook("The Courts of Chaos", "Zelazny", 900);

            books.Add(ZelaznyEBook2);
            //-------------------------------------------------------------------------------------------
            //Создаем журналы
            PaperJournal WhiteDwarf1 = new PaperJournal("WhiteDwarf1", "GW", 500, 2019, 12);

            books.Add(WhiteDwarf1);
            PaperJournal WhiteDwarf2 = new PaperJournal("WhiteDwarf2", "GW", 500, 2020, 1);

            books.Add(WhiteDwarf2);
            PaperJournal WhiteDwarf3 = new PaperJournal("WhiteDwarf3", "GW", 500, 2019, 4);

            books.Add(WhiteDwarf3);
            PaperJournal WhiteDwarf4 = new PaperJournal("WhiteDwarf4", "GW", 500, 2019, 5);

            books.Add(WhiteDwarf4);
            PaperJournal WhiteDwarf5 = new PaperJournal("WhiteDwarf5", "GW", 500, 2019, 6);

            books.Add(WhiteDwarf5);
            //-------------------------------------------------------------------------------------------
            return(books);
        }