Exemplo n.º 1
0
        public bool FreeSpotsExists()
        {
            var db = new SpaceParkDbContext();

            FreeSpots = db.ParkingSpots.Where(sp => !sp.IsOccupied).ToList();
            return(FreeSpots.Count == 0 ? false : true);
        }
Exemplo n.º 2
0
        public void AddParkingRegistration(string parkingTime, string spaceship, ParkingSpot chosenParkingSpot)
        {
            ParkingRegistration parkingRegistration = new ParkingRegistration();

            parkingRegistration.ParkingStartTime = DateTime.Now;
            parkingRegistration.ParkingEndTime   = DateTime.Now + TimeSpan.Parse(parkingTime);

            parkingRegistration.ParkingFee = Convert.ToDecimal(TimeSpan.Parse(parkingTime).TotalHours * 50);
            parkingRegistration.IsPaid     = false;

            parkingRegistration.SpaceShipName = spaceship;

            var db          = new SpaceParkDbContext();
            var parkingSpot = db.ParkingSpots.Where(sp => sp == chosenParkingSpot).Single();

            parkingSpot.IsOccupied          = true;
            parkingRegistration.ParkingSpot = parkingSpot;
            try
            {
                var userEntity = db.Users.Where(u => u.name.ToLower() == User.name.ToLower()).Single();
                parkingRegistration.User = userEntity;
            }
            catch
            {
                parkingRegistration.User = User;
            }

            db.Add(parkingRegistration);
            db.SaveChanges();
        }
Exemplo n.º 3
0
        public void EndParkingRegistration()
        {
            var db = new SpaceParkDbContext();
            var parkingRegistrationEntity = db.ParkingRegistrations.Where(p => p.ParkingRegistrationID == ActiveParking.ParkingRegistrationID).Include(p => p.ParkingSpot).Single();

            parkingRegistrationEntity.ParkingEndTime = DateTime.Now;
            var timeParkedInHours = (parkingRegistrationEntity.ParkingEndTime - parkingRegistrationEntity.ParkingStartTime).TotalHours;

            parkingRegistrationEntity.ParkingFee = Convert.ToDecimal(timeParkedInHours * 50);
            ActiveParking = parkingRegistrationEntity;
            var parkingSpot = db.ParkingSpots.Where(sp => sp.ParkingSpotID == parkingRegistrationEntity.ParkingSpot.ParkingSpotID).Single();

            db.Update(parkingRegistrationEntity);
            parkingSpot.IsOccupied = false;
            db.Update(parkingSpot);
            db.SaveChanges();
        }
Exemplo n.º 4
0
        public void UpdateParkingRegistration(string newTime)
        {
            var db = new SpaceParkDbContext();
            var parkingRegistrationEntity = db.ParkingRegistrations.Where(p => p == ActiveParking).Single();
            var newEndTime = parkingRegistrationEntity.ParkingEndTime + TimeSpan.Parse(newTime);

            if (newEndTime < DateTime.Now)
            {
                parkingRegistrationEntity.ParkingEndTime = DateTime.Now;
            }
            else
            {
                parkingRegistrationEntity.ParkingEndTime += TimeSpan.Parse(newTime);
            }

            db.Update(parkingRegistrationEntity);
            db.SaveChanges();
        }
Exemplo n.º 5
0
        public bool UserHasActiveParking()
        {
            var db = new SpaceParkDbContext();

            try
            {
                var userEntity = db.Users.Where(u => u.name.ToLower() == User.name.ToLower()).Single();
                var parkingRegistrationEntitys = db.ParkingRegistrations.Where(p => p.User == userEntity).ToList();
                foreach (var parkingRegistrationEntity in parkingRegistrationEntitys)
                {
                    if (parkingRegistrationEntity.ParkingEndTime > DateTime.Now)
                    {
                        ActiveParking = parkingRegistrationEntity;
                        return(true);
                    }
                }
                return(false);
            }
            catch { return(false); }
        }