// GET: Search by regnbr
        public IActionResult Search(string Registreringsnummer)
        {
            IEnumerable <ParkedVehicle> parkedVehicleList = null; // = null;

            ViewData["Title_Reg"] = "Registreringsnummer";        // Fält- och label-namn
            ViewData["RegNbr"]    = "";                           // Ev. indata

            if (!string.IsNullOrEmpty(Registreringsnummer))
            {
                VehiclePriceViewModel vehicle = new VehiclePriceViewModel();
                ParkedVehicle         fordon  = _context.ParkedVehicle
                                                .FirstOrDefault(v => v.RegistrationNumber == Registreringsnummer);

                if (fordon != null)
                {
                    vehicle.ParkedVehicle = fordon;
                    vehicle.CurrentPrice  = CalculateParkingCost(fordon.StartTime);

                    return(View("Details", vehicle));
                }
                else
                {
                    ViewData["RegNbr"] = Registreringsnummer;

                    parkedVehicleList = (from p in _context.ParkedVehicle
                                         where p.RegistrationNumber.Contains(Registreringsnummer)
                                         orderby p.RegistrationNumber
                                         select p);
                }
            }

            return(View(parkedVehicleList));
        }
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var parkedVehicle = await _context.ParkedVehicle
                                .Include(p => p.VehicleType)
                                .Include(p => p.Member)
                                .FirstOrDefaultAsync(m => m.Id == id);

            var parkedVehicleCost = new VehiclePriceViewModel();
            var parkedVehicleDel  = await _context.ParkedVehicle.FindAsync(id);

            if (parkedVehicleDel == null)
            {
                //in case of reloading the reciept page, redirect to index
                return(RedirectToAction(nameof(Index)));
            }
            _context.ParkedVehicle.Remove(parkedVehicleDel);
            await _context.SaveChangesAsync();


            parkedVehicleCost.ParkedVehicle = parkedVehicle;
            var price = parkedVehicle.VehicleType.ParkingPrice;

            parkedVehicleCost.CurrentPrice = CalculateParkingCost(parkedVehicle.StartTime, price);
            parkedVehicleCost.Member       = parkedVehicle.Member;
            var timeSpan = DateTime.Now - parkedVehicle.StartTime;

            parkedVehicleCost.ParkedMinutes = timeSpan.ToString("c").Remove(5);
            return(View("Receipt", parkedVehicleCost));
        }
        // GET: ParkedVehicles2/Delete/5
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var parkedVehicle = await _context.ParkedVehicle
                                .Include(p => p.VehicleType)
                                .Include(p => p.Member)
                                .FirstOrDefaultAsync(m => m.Id == id);

            var parkedVehicleCost = new VehiclePriceViewModel();

            if (parkedVehicle != null)
            {
                ViewData["Title"] = "Checkar ut fordonet";
                parkedVehicleCost.ParkedVehicle = parkedVehicle;
                parkedVehicleCost.CurrentPrice  = CalculateParkingCost(parkedVehicle.StartTime, parkedVehicle.VehicleType.ParkingPrice);
            }
            else
            {
                TempData["Text"] = "Hittar inte fordonet - är det redan utcheckat?";
            }

            return(View(parkedVehicleCost));
        }
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            ParkedVehicle parkedVehicle;

            parkedVehicle = await _context.ParkedVehicle.FindAsync(id);

            _context.ParkedVehicle.Remove(parkedVehicle);
            await _context.SaveChangesAsync();

            //return RedirectToAction(nameof(Index));
            var parkedVehicleCost = new VehiclePriceViewModel();

            parkedVehicleCost.ParkedVehicle = parkedVehicle;
            parkedVehicleCost.CurrentPrice  = CalculateParkingCost(parkedVehicle.StartTime);
            parkedVehicleCost.Member        = parkedVehicle.Member;

            return(View("Receipt", parkedVehicleCost)); //doesn't currently work while reloading
        }
        // GET: ParkedVehicles/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var parkedVehicle = await _context.ParkedVehicle
                                .FirstOrDefaultAsync(m => m.Id == id);

            if (parkedVehicle == null)
            {
                return(NotFound());
            }
            var parkedVehicleCost = new VehiclePriceViewModel();

            parkedVehicleCost.ParkedVehicle = parkedVehicle;
            parkedVehicleCost.CurrentPrice  = CalculateParkingCost(parkedVehicle.StartTime);
            return(View(parkedVehicleCost));
        }