Ejemplo n.º 1
0
        /// <summary>
        /// Method for populating View service combo box
        /// </summary>
        /// <param name="air">AirExpress service</param>
        /// <param name="truck">UnclesTruck service</param>
        /// <param name="snail">SnailService service</param>
        /// <returns></returns>
        private List <IDeliveryService> GetServicesForComboBox(AirExpress air, UnclesTruck truck, SnailService snail)
        {
            AirExpress   newAir   = air;
            UnclesTruck  newTruck = truck;
            SnailService newSnail = snail;

            List <IDeliveryService> services = new List <IDeliveryService>();

            services.Add(newAir);
            services.Add(newTruck);
            services.Add(newSnail);

            return(services);
        }
Ejemplo n.º 2
0
        public ActionResult CalculateShipping(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                /*string s = "call calculate shipping here!";
                 * double cost = 7;
                 * viewModel.ShippingCost = cost;
                 * viewModel.ShippingMessage = s;*/

                DeliveryService service;
                uint            numRefuels;
                uint            shippingDistance;

                if (collection["ShippingMethods"].ToString() == "Snail Service")
                {
                    service = new SnailService((IShippingVehicle)(new Snail()));
                }
                else if (collection["ShippingMethods"].ToString() == "Uncle's Truck")
                {
                    service = new UnclesTruck((new Truck()));
                }
                else if (collection["ShippingMethods"].ToString() == "Air Express")
                {
                    service = new AirExpress((new Plane()));
                }

                //viewModel.ShippingZipCode = service.ShippingVehicle.ZipCode;
                viewModel.ShippingDistance = service.ShippingVehicle.MaxDistancePerRefuel;
                viewModel.CostRefills      = service.CostPerRefuel;

                return(View(viewModel));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 3
0
 public ShippingViewModel(IShippingService ShippingService, AirExpress air, UnclesTruck truck, SnailService snail)
 {
     // Dependency Injection preferred for the model
     shippingService = ShippingService;
     // Declare variables for Combo box
     ServiceForComboBox = new ObservableCollection <IDeliveryService>(GetServicesForComboBox(air, truck, snail));
     // The combo box needs an initial value so that it is not empty when the application is started
     ServiceName = ServiceForComboBox.First().ToString();
     // Make sure that the UI is refreshed to reflect the initial destination zip code
     DestinationZip = shippingService.ShippingLocation.DestinationZipCode;
 }