// POST: ShipmentCostCalculator public ActionResult ShipmentCostCalculator(CalculatorShipmentViewModel shipment) { shipment.Destinations = PopulateDestinationsDropDownList().ToList(); shipment.ServiceTypes = PopulateServiceTypesDropDownList().ToList(); shipment.CurrencyCodes = PopulateCurrenciesDropDownList().ToList(); for (int i = 0; i < 10; i++) { shipment.Packages[i].PackageTypeSizes = PopulatePackageTypeSizesDropDownList().ToList(); } shipment.ShipmentCost = 0; ViewBag.NumberOfPackages = shipment.NumberOfPackages; for (int i = 0; i < 10; i++) { if (i >= shipment.NumberOfPackages || shipment.Packages[i].Weight == 0) { shipment.Packages[i].PackageTypeSizeID = 1; shipment.Packages[i].Weight = 0; continue; } PackageTypeSize packageTypeSize = db.PackageTypeSizes.Find(shipment.Packages[i].PackageTypeSizeID); ServicePackageFee servicePackageFee = db.ServicePackageFees.First(s => (s.ServiceTypeID == shipment.ServiceTypeID) && (s.PackageTypeID == packageTypeSize.PackageTypeID)); decimal packageCost = 0; float weightLimit = db.PackageTypeSizes.Find(shipment.Packages[i].PackageTypeSizeID).WeightLimit; packageCost = (decimal)shipment.Packages[i].Weight * servicePackageFee.Fee; if (weightLimit > 0 && shipment.Packages[i].Weight > weightLimit) { packageCost += 500; } packageCost = (packageCost < servicePackageFee.MinimumFee) ? servicePackageFee.MinimumFee : packageCost; packageCost = ConvertCurrency(shipment.CurrencyCode, packageCost); shipment.Packages[i].PackageCost = packageCost; shipment.ShipmentCost += packageCost; } return(View(shipment)); }
// GET: ShipmentCostCalculator public ActionResult ShipmentCostCalculator() { var shipmentCostCalculator = new CalculatorShipmentViewModel(); shipmentCostCalculator.Packages = new CalculatorPackageViewModel[10]; shipmentCostCalculator.Destinations = PopulateDestinationsDropDownList().ToList(); shipmentCostCalculator.ServiceTypes = PopulateServiceTypesDropDownList().ToList(); shipmentCostCalculator.CurrencyCodes = PopulateCurrenciesDropDownList().ToList(); ViewBag.NumberOfPackages = 1; shipmentCostCalculator.NumberOfPackages = 1; shipmentCostCalculator.ShipmentCost = 0; for (int i = 0; i < 10; i++) { shipmentCostCalculator.Packages[i] = new CalculatorPackageViewModel(); shipmentCostCalculator.Packages[i].PackageTypeSizes = PopulatePackageTypeSizesDropDownList().ToList(); shipmentCostCalculator.Packages[i].PackageCost = 0; } return(View(shipmentCostCalculator)); }