Пример #1
0
        public async Task <IActionResult> PriceMatch(long?id)
        {
            await AuthenticateUserLogin(true);

            long    vehicleId = (long)id;
            Vehicle vehicle   = (Vehicle)await CommandFactory.CreateCommand(CommandFactory.GET_VEHICLE, vehicleId, DbContext).Execute();

            int newCostPerDay = -1;

            if (!String.IsNullOrEmpty(vehicle.VehicleComparisonSourceURL))
            {
                PriceMatchScraper priceMatchScraper = new PriceMatchScraper(vehicle.VehicleComparisonSourceURL);
                await priceMatchScraper.StartAsync();

                if (!String.IsNullOrEmpty(priceMatchScraper.PriceString))
                {
                    string priceStringToConvert = priceMatchScraper.PriceString.Replace("GBP", "");
                    priceStringToConvert = priceStringToConvert.Trim();
                    newCostPerDay        = Int32.Parse(priceStringToConvert);
                }
            }

            if (newCostPerDay <= 0)
            {
                TempData["errormessage"] = "Unable to update vehicle cost per day. Please try again.";
                return(RedirectToAction("Index", "Home"));
            }

            int vehicleCostUpdated = (int)await CommandFactory.CreateCommand(CommandFactory.UPDATE_VEHICLE_COST_PER_DAY, DbContext, vehicleId, newCostPerDay).Execute();

            if (vehicleCostUpdated < 1)
            {
                TempData["errormessage"] = "Unable to update vehicle cost per day. Please try again.";
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                TempData["successmessage"] = "Vehicle Cost Updated!";
                return(RedirectToAction("Index", "Home"));
            }
        }
Пример #2
0
        public async Task <IActionResult> PriceMatch()
        {
            await AuthenticateUserLogin(true);

            PriceMatchViewModel priceMatchViewModel = new PriceMatchViewModel();

            priceMatchViewModel.PriceMatchVehicles = new List <PriceMatchVehiclesViewModel>();

            List <Vehicle> vehicles = (List <Vehicle>) await CommandFactory.CreateCommand(CommandFactory.GET_VEHICLES, DbContext).Execute();

            foreach (Vehicle vehicle in vehicles)
            {
                if (!String.IsNullOrEmpty(vehicle.VehicleComparisonSourceURL))
                {
                    PriceMatchScraper priceMatchScraper = new PriceMatchScraper(vehicle.VehicleComparisonSourceURL);
                    await priceMatchScraper.StartAsync();

                    if (!String.IsNullOrEmpty(priceMatchScraper.PriceString))
                    {
                        PriceMatchVehiclesViewModel priceMatchVehiclesViewModel = new PriceMatchVehiclesViewModel();
                        priceMatchVehiclesViewModel.VehicleId             = (int)vehicle.Id;
                        priceMatchVehiclesViewModel.VehicleDescription    = (vehicle.Manufacturer + " " + vehicle.Model);
                        priceMatchVehiclesViewModel.VehicleTypeCostPerDay = (Decimal.ToInt32(vehicle.CostPerDay).ToString() + " GBP");
                        priceMatchVehiclesViewModel.PriceToMatch          = priceMatchScraper.PriceString;

                        priceMatchViewModel.PriceMatchVehicles.Add(priceMatchVehiclesViewModel);
                    }
                }
            }

            if (priceMatchViewModel.PriceMatchVehicles.Count > 0)
            {
                return(View(priceMatchViewModel));
            }
            else
            {
                TempData["errormessage"] = "No Price Match Data Available.";
                return(RedirectToAction("Index", "Home"));
            }
        }