Esempio n. 1
0
        // GET: Garages/UnParked/
        public IActionResult UnParkedOLD(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            // Find the vehicle id
            //var vehicle = await dbGarage.Vehicle.FirstOrDefaultAsync(v => v.VehicleId == id);
            //var parkedV = await dbGarage.ParkingPlace.FirstOrDefaultAsync(p => p.ParkingPlaceId == vehicle.VehicleId);

            // V > -- PPV -- < PP

            var vehicle = dbGarage.Vehicle.Where(i => i.VehicleId == id).FirstOrDefault();

            if (vehicle != null)
            {
                vehicle.CheckOutTime = DateTime.Now;
                vehicle.IsParked     = false;
            }


            // find the parking place

            var parkedV = dbGarage.ParkingPlace.Where(pv => pv.VehicleId == id).FirstOrDefault();

            if (parkedV != null)
            {
                parkedV.IsOccupied = false;
                parkedV.VehicleId  = null;
            }

            dbGarage.SaveChanges();

            var ppv = dbGarage.ParkingPlaceVehicles.Where(p => p.VehicleId == id).FirstOrDefault();

            if (ppv != null)
            {
                dbGarage.Remove(ppv);
                dbGarage.SaveChanges();
            }

            if (vehicle == null)
            {
                return(NotFound());
            }

            return(View());
        }
Esempio n. 2
0
        //[HttpPost]
        public IActionResult Park(string regNum)
        {
            var vehicle = _context.Vehicle.Find(regNum);

            if (vehicle != null)
            {
                if (vehicle.ParkedFlag == true)
                {
                    vehicle.ParkedFlag    = false;
                    vehicle.DepartureTime = DateTime.Now;
                }
                else
                {
                    vehicle.ParkedFlag  = true;
                    vehicle.ArrivalTime = DateTime.Now;
                }
                _context.SaveChanges();
                return(RedirectToAction(nameof(Profile), "Owner", new { id = vehicle.MemberNumber }));
            }
            return(NotFound());
        }