Example #1
0
        public void CreateRideBooking(RideBooking booking)
        {
            Booking rideBooking = _mapper.Map <RideBooking, Booking>(booking);

            rideBooking.Id     = GenerateId();
            rideBooking.Status = BookingStatus.Requested;

            _repository.Post(rideBooking);

            User user = _userRepository.Get(rideBooking.BookingUserId);

            if (user != null)
            {
                user.LastBookingId = rideBooking.Id;
                _userRepository.Put(user);
            }

            OfferRide RideOffer = _rideOffersRepository.Get(booking.RideOfferId);

            if (RideOffer != null)
            {
                RideOffer.AvailableSeats = RideOffer.AvailableSeats - booking.Seats;
                _rideOffersRepository.Put(RideOffer);
            }
        }
Example #2
0
        public void SetStatusOfBooking(long bookingId, long rideOfferId, BookingStatus status)
        {
            Booking UserBooking = _repository.Get(bookingId);

            UserBooking.Status = status;
            _repository.Put(UserBooking);
            if (status == BookingStatus.Rejected)
            {
                OfferRide RideOffer = _rideOffersRepository.Get(rideOfferId);
                RideOffer.AvailableSeats = RideOffer.AvailableSeats + UserBooking.Seats;
                _rideOffersRepository.Put(RideOffer);
            }
        }
Example #3
0
        public void CreateRideOffer(long userId, RideOffer rideOffer)
        {
            OfferRide NewRideOffer = _mapper.Map <RideOffer, OfferRide>(rideOffer);

            NewRideOffer.RideOfferId = GenerateId();
            NewRideOffer.HostId      = userId;

            _repository.Post(NewRideOffer);

            foreach (string area in rideOffer.Route)
            {
                Place NewPlace = new Place
                {
                    AreaName    = area,
                    RideOfferId = NewRideOffer.RideOfferId
                };
                NewRideOffer.Route.Add(NewPlace);
            }
            _routeRepository.AddRange(NewRideOffer.Route);
            User user = _userRepository.Get(userId);

            user.LastOfferRideId = NewRideOffer.RideOfferId;
            _userRepository.Put(user);
        }
 public void UpdateUser(User user)
 {
     _repository.Put(user);
 }