コード例 #1
0
        public Product GetProduct(string name, Zone zone)
        {
            Product      product   = new Product();
            IkeaWSClient ikeaws    = new IkeaWSClient();
            double       ikeaPrice = ikeaws.search(name);

            if (ikeaPrice == 0)
            {
                return(null);
            }
            product.Name         = name;
            product.ProductPrice = ikeaPrice;
            double volume = 0;
            double weight = 0;

            foreach (var piece in ikeaws.pieces(name))
            {
                volume += piece.volume * piece.amount;
                weight += piece.weight * piece.amount;
            }

            double distance = 0;

            if (zone == Zone.CENTER)
            {
                distance = 50;
            }
            if (zone == Zone.EAST)
            {
                distance = 75;
            }
            else
            {
                distance = 100;
            }

            FedexWSClient fedexws  = new FedexWSClient();
            var           shipping = fedexws.shipping(volume, weight, distance);

            product.ShippingPrice = shipping.price;

            //Update statistics
            DataServiceSoapClient dataws = new DataServiceSoapClient();

            product.Visits = dataws.GetProductStatistics(name);
            if (product.Visits == 0)
            {
                dataws.CreateProductStatistics(name);
            }
            else
            {
                dataws.UpdateProductStatistics(name);
            }

            return(product);
        }