Esempio n. 1
0
        public LiftRequestController(CarPoolContext carPoolContext, Client nexmoSmsClient)
        //public LiftRequestController(CarPoolContext carPoolContext)

        {
            _carPoolContext = carPoolContext;
            _nexmoSmsClient = nexmoSmsClient;
        }
Esempio n. 2
0
 public Ride GetRideByRideId(string rideId)
 {
     using (var db = new CarPoolContext())
     {
         return(db.Rides.Where(r => r.Id == rideId).SingleOrDefault());
     }
 }
 public List <ViaPoint> GetViaPointsByName(string name)
 {
     using (var db = new CarPoolContext())
     {
         return(db.Cities.Where(c => c.CityName == name).ToList());
     }
 }
Esempio n. 4
0
 public List <Ride> GetAllRides()
 {
     using (var db = new CarPoolContext())
     {
         return(db.Rides.ToList());
     }
 }
 public List <ViaPoint> GetAllViaPoints()
 {
     using (var db = new CarPoolContext())
     {
         return(db.Cities.ToList());
     }
 }
 public Booking GetBookingbyBookingId(string bookingId)
 {
     using (var db = new CarPoolContext())
     {
         return(db.Bookings.Where(b => b.Id == bookingId).SingleOrDefault());
     }
 }
Esempio n. 7
0
 public User GetUserById(string userId)
 {
     using (var db = new CarPoolContext())
     {
         return(db.Users.Where(user => user.Id == userId).Include(s => s.Car).SingleOrDefault());
     }
 }
Esempio n. 8
0
 public List <Ride> GetRidesByUserId(string userId)
 {
     using (var db = new CarPoolContext())
     {
         return(db.Rides.Where(r => r.UserId == userId).ToList());
     }
 }
Esempio n. 9
0
        public void RemoveRide(Ride ride)
        {
            using (var db = new CarPoolContext())
            {
                db.Rides.Remove(ride);

                db.Cities.RemoveRange(db.Cities.Where(c => c.RideID == ride.Id));

                db.Bookings.RemoveRange(db.Bookings.Where(b => b.RideId == ride.Id));

                //foreach (ViaPoint city in db.Cities)
                //{
                //    if (city.RideID == ride.Id)
                //        db.Cities.Remove(city);
                //}

                //foreach (Booking booking in db.Bookings)
                //{
                //    if (booking.RideId == ride.Id)
                //        db.Bookings.Remove(booking);
                //}

                db.SaveChanges();
            }
        }
Esempio n. 10
0
 public List <Booking> GetAllBookings()
 {
     using (var db = new CarPoolContext())
     {
         return(db.Bookings.ToList());
     }
 }
Esempio n. 11
0
 public List <Booking> GetBookingsByUserId(string userId)
 {
     using (var db = new CarPoolContext())
     {
         return(db.Bookings.Where(b => b.UserId == userId).ToList());
     }
 }
Esempio n. 12
0
 public List <Booking> GetBookingsByRideId(string rideId)
 {
     using (var db = new CarPoolContext())
     {
         return(db.Bookings.Where(b => b.RideId == rideId).ToList());
     }
 }
Esempio n. 13
0
 public List <Booking> GetBookingsByUserIdAndRideId(Booking booking)
 {
     using (var db = new CarPoolContext())
     {
         return(db.Bookings.Where(b => b.UserId == booking.UserId && b.RideId == booking.RideId).ToList());
     }
 }
 public List <ViaPoint> GetAllViaPointsByBookedRideId(string rideId)
 {
     using (var db = new CarPoolContext())
     {
         return(db.Cities.Where(c => c.RideID == rideId).ToList());
     }
 }
Esempio n. 15
0
        public void RemoveUser(string userId)
        {
            using (var db = new CarPoolContext())
            {
                db.Users.Remove(GetUserById(userId));

                foreach (Ride ride in db.Rides)
                {
                    if (ride.UserId == userId)
                    {
                        db.Rides.Remove(ride);
                    }
                    foreach (ViaPoint city in db.Cities)
                    {
                        if (city.RideID == ride.Id)
                        {
                            db.Cities.Remove(city);
                        }
                    }
                }

                db.Bookings.RemoveRange(db.Bookings.Where(b => b.UserId == userId));

                //foreach (Booking booking in db.Bookings)
                //{
                //    if (booking.UserId == userId)
                //        db.Bookings.Remove(booking);
                //}

                db.SaveChanges();
            }
        }
Esempio n. 16
0
 public void AddBooking(Booking booking)
 {
     using (var db = new CarPoolContext())
     {
         db.Bookings.Add(booking);
         db.SaveChanges();
     }
 }
Esempio n. 17
0
        public static List <CarPoolInfo> getCarPoolInfos(CarPoolContext carPoolContext, PersonContext personContext)
        {
            carPoolContext.Database.EnsureCreated();
            List <CarPool>     carPools     = carPoolContext.CarPools.ToList();
            List <CarPoolInfo> carPoolInfos = carPools.Select(c => getCarPoolInfoBase(carPoolContext, personContext, c)).ToList();

            return(carPoolInfos);
        }
Esempio n. 18
0
 public void CancelBooking(Booking booking)
 {
     using (var db = new CarPoolContext())
     {
         db.Bookings.Remove(booking);
         db.SaveChanges();
     }
 }
Esempio n. 19
0
 public void AddUser(User user)
 {
     using (var db = new CarPoolContext())
     {
         db.Add(user);
         db.SaveChanges();
     }
 }
Esempio n. 20
0
        public bool IsUnderOfferring(int userId)
        {
            bool result = false;

            using (var context = new CarPoolContext()){
                result = context.Offerrings.Where(e => e.UserId == userId && e.Active).Count() > 0;
            }
            return(result);
        }
Esempio n. 21
0
 public void UpdateBookingStatus(Booking booking)
 {
     using (var db = new CarPoolContext())
     {
         Booking currentBooking = db.Bookings.Where(b => b.Id == booking.Id).SingleOrDefault();
         currentBooking.Status = booking.Status;
         db.SaveChanges();
     }
 }
        public void SetUp()
        {
            var dbContextOptions = new DbContextOptionsBuilder <CarPoolContext>()
                                   .UseInMemoryDatabase(databaseName: "TestDatabase")
                                   .Options;

            _carPoolContext = new CarPoolContext(dbContextOptions);
            _journeyService = new JourneyService(_carPoolContext);
        }
Esempio n. 23
0
        public List <Offerring> GetAll()
        {
            List <Offerring> offerrings = new List <Offerring> ();

            using (var context = new CarPoolContext()) {
                offerrings = context.Offerrings.Include(e => e.Bookings).ThenInclude(e => e.User).Include(e => e.User).Include(e => e.Vechicles).Include(e => e.ViaPoints).ToList();
            }
            return(offerrings);
        }
 public void UpdateAvailableSeat(ViaPoint city, int updatedSeats)
 {
     using (var db = new CarPoolContext())
     {
         ViaPoint City = db.Cities.Where(c => c.Id == city.Id).Single();
         City.SeatAvailable = updatedSeats;
         db.SaveChanges();
     }
 }
Esempio n. 25
0
        public List <Offerring> GetByUserId(int id)
        {
            List <Offerring> offers = null;

            using (var context = new CarPoolContext()) {
                offers = context.Offerrings.Where(e => e.UserId == id).Include(e => e.User).Include(e => e.Source).Include(e => e.Destination).Include(e => e.Bookings).ThenInclude(e => e.Source).Include(e => e.Bookings).ThenInclude(e => e.Destination).Include(e => e.Bookings).ThenInclude(e => e.User).ToList();
            }
            return(offers);
        }
 public bool Delete(int id)
 {
     using (var _context = new CarPoolContext())
     {
         _context.Vechicles.FirstOrDefault(e => e.Id == id).Active = false;
         _context.SaveChanges();
     }
     return(true);
 }
        public Vechicles GetById(int id)
        {
            Vechicles vehicle;

            using (var context = new CarPoolContext())
            {
                vehicle = context.Vechicles.Find(id);
            }
            return(vehicle);
        }
        public List <Vechicles> GetAll()
        {
            List <Vechicles> vechicles = new List <Vechicles>();

            using (var context = new CarPoolContext())
            {
                vechicles = context.Vechicles.ToList();
            }
            return(vechicles);
        }
Esempio n. 29
0
        public bool Delete(int id)
        {
            bool result = false;

            using (var context = new CarPoolContext()) {
                context.Offerrings.FirstOrDefault(e => e.Id == id).Active = false;
                context.SaveChanges();
                result = true;
            }
            return(result);
        }
Esempio n. 30
0
        public bool StartRide(int OfferId)
        {
            bool result = false;

            using (var context = new CarPoolContext()) {
                context.Offerrings.Where(e => e.Id == OfferId).Single().IsRideStarted = true;
                context.SaveChanges();
                result = true;
            }
            return(result);
        }