Beispiel #1
0
        public void AddConsignment()
        {
            Consignment        pr1          = new Consignment("Молоко", 120, 40);
            Consignment        pr2          = new Consignment("Вода", 78, 19);
            Consignment        pr3          = new Consignment("Мороженное", 23, 140);
            List <Consignment> consignment1 = new List <Consignment>()
            {
                pr1, pr2, pr3
            };

            _service.AddConsignment(consignment1, "7я");

            Consignment        pr4          = new Consignment("Молоко", 120, 59);
            Consignment        pr5          = new Consignment("Вода", 78, 27.66);
            List <Consignment> consignment2 = new List <Consignment>()
            {
                pr4, pr5
            };

            _service.AddConsignment(consignment2, "Окей");

            Consignment        pr6          = new Consignment("Молоко", 120, 92);
            Consignment        pr7          = new Consignment("Вода", 78, 19.77);
            Consignment        pr8          = new Consignment("Мороженное", 23, 133);
            List <Consignment> consignment3 = new List <Consignment>()
            {
                pr6, pr7, pr8
            };

            _service.AddConsignment(consignment3, "Лента");
        }
Beispiel #2
0
        public Double BuyConsignment(List <Product> products, String store)
        {
            List <String> productsInfo = resource.GetProductsInfo(DBFormat(store));
            Double        summ         = 0.0;

            List <Int32> boughtAmount = new List <Int32>();

            foreach (var product in products)
            {
                Consignment consignmentInfo = GetConsignment(productsInfo, product.Product_);
                if (consignmentInfo == null)
                {
                    throw new EmptyResponseException();
                }
                if (consignmentInfo.amount < product.Amount_)
                {
                    throw new NotEnoughException();
                }

                summ += consignmentInfo.price * product.Amount_;
                boughtAmount.Add(product.Amount_);
            }

            for (int i = 0; i < products.Count; i++)
            {
                resource.DecreaseAmount(DBFormat(products[i].Product_), DBFormat(store), boughtAmount[i]);
            }

            return(summ);
        }
Beispiel #3
0
        Consignment GetConsignment(List <String> storeStock, String productName)
        {
            Consignment consignment = null;

            foreach (var x in storeStock)
            {
                String[] data = x.Split("$");
                if (Format(data[0]).Equals(Format(productName)))
                {
                    Double price  = Double.Parse(data[1]);
                    Int32  amount = Int32.Parse(data[2]);

                    consignment = new Consignment(data[0], amount, price);
                    break;
                }
            }

            return(consignment);
        }