Пример #1
0
        /// <summary>
        /// Main Method.
        /// </summary>
        public static void Main()
        {
            // Add CountryVatTax countries - id, vat, isDefault
            CountryVatTax bg = new CountryVatTax(1, 20, true);

            // Add countries to list
            List<CountryVatTax> countriesList = new List<CountryVatTax>() { bg };

            // Initialise VatTaxCalculator with the countries list
            VatTaxCalculator calc = new VatTaxCalculator(countriesList);

            // Add products - id, name, quantity, price, country
            Product prod1 = new Product(0, "prod", 5, 10, bg);

            // Add products to list
            List<Product> productsList = new List<Product>() { prod1 };

            // Initialise a new Inventory with the products list
            ShopInventory newInventory = new ShopInventory(productsList);

            // Add product id and quantity to orderdict
            Dictionary<int, int> orderdict = new Dictionary<int, int> { { 0, 2 } };

            Order newOrder = new Order(orderdict);
        }
        /// <summary>
        /// Takes and order.
        /// </summary>
        /// <param name="order">Order to process.</param>
        /// <returns>The order price.</returns>
        public double RequestOrder(Order order)
        {
            // Takes an order and returns the order price
            double sum = (from id in order.ProductIds
                          from prod in this.productsList.Keys
                          where prod.ProductId == id && order.ProductQuantities[order.ProductIds.IndexOf(id)] <= prod.Quantity
                          select prod.PriceWithTax * order.ProductQuantities[order.ProductIds.IndexOf(id)]).Sum();

            if (Math.Abs(sum) > 0.001)
            {
                return sum;
            }

            Console.WriteLine("ERROR: None of the items you ordered are available in the requested quantities !");
            return -1;
        }
Пример #3
0
        static void Main(string[] args)
        {
            CountryVatTax obj = new CountryVatTax(1, 20, false);
            CountryVatTax obj1 = new CountryVatTax(2, 10, true);
            List<CountryVatTax> countries = new List<CountryVatTax>() { obj, obj1 };
            Calculator calcObj = new Calculator(countries);
            calcObj.Calc(5);
            calcObj.Calc(5, 1);

            Product product = new Product(5, 1, "Хак", 5, 1, countries);
            Product product2 = new Product(10, 1, "България", 5, 2, countries);
            ShopInventory newShopInvertory = new ShopInventory(product);
            Console.WriteLine("If all products of that type are sold out, the profil you will gain is = {0}", newShopInvertory.Audit());

            Order firstOrder = new Order(1, 3);
            newShopInvertory.RequestOrder(firstOrder);
        }