Example #1
0
        }//End Add() [Post]

        //   R e a d
        public IActionResult ListRepairs(int vehicleId)
        {
            IQueryable <Repair> vehicleRepairs = _repository.GetVehicleRepairs(vehicleId);

            float total = 0;

            foreach (Repair r in vehicleRepairs)
            {
                if (r.LaborCost != null)
                {
                    total += r.LaborCost.Value;
                }

                if (r.PartsCost != null)
                {
                    total += r.PartsCost.Value;
                }
            }

            ViewBag.TotalRepairCost = total.ToString("C");

            Vehicle vehicle = _vehicleRepository.GetVehicleById(vehicleId);

            ViewBag.VehicleNickName = vehicle.NickName;
            ViewBag.VehicleId       = vehicle.Id;

            return(View(vehicleRepairs));
        }//End ListRepairs()
        }//End UserVehicles()

        public IActionResult Details(int vehicleId)
        {
            float repairsCost = 0;
            float upgradeCost = 0;
            float vehicleCost = 0;
            float totalCost   = 0;

            IQueryable <Repair> repairs = _repairRepository.GetVehicleRepairs(vehicleId);

            foreach (Repair r in repairs)
            {
                if (r.PartsCost != null)
                {
                    repairsCost += r.PartsCost.Value;
                }

                if (r.LaborCost != null)
                {
                    repairsCost += r.LaborCost.Value;
                }
            }
            ViewBag.RepairsCost = repairsCost.ToString("C");

            IQueryable <Upgrade> upgrades = _upgradeRepository.GetVehicleUpgrades(vehicleId);

            foreach (Upgrade u in upgrades)
            {
                if (u.PartsCost != null)
                {
                    upgradeCost += u.PartsCost.Value;
                }

                if (u.LaborCost != null)
                {
                    upgradeCost += u.LaborCost.Value;
                }
            }
            ViewBag.UpgradesCost = upgradeCost.ToString("C");

            Vehicle v = _repository.GetVehicleById(vehicleId);

            if (v.PurchasePrice != null)
            {
                vehicleCost = v.PurchasePrice.Value;
            }
            totalCost         = vehicleCost + repairsCost + upgradeCost;
            ViewBag.TotalCost = totalCost.ToString("C");

            return(View(v));
        }//End VehicleDetails