Exemplo n.º 1
0
        public BookingResponse SaveBookingFareType(int bookingId, FareType fareType)
        {
            try
            {
                using (var db = new LomsContext())
                {
                    var booking = GetBooking(db, bookingId);

                    booking.FareType = fareType;
                    var promotionId = booking.FareInfo.Items.First(i => i.FareTypeId == (byte)fareType).PromotionId;
                    booking.FarePromotionId = promotionId.HasValue ? promotionId.Value : 0;

                    db.BookingPaymentItems.Where(p => p.BookingId == bookingId).ForEach(item => db.BookingPaymentItems.DeleteObject(item));

                    //remove charge info and incompleted credit card transactions
                    var chargeInfo = db.BookingChargeInfoes.SingleOrDefault(ci => ci.BookingId == bookingId);
                    if (chargeInfo != null)
                        db.BookingChargeInfoes.DeleteObject(chargeInfo);
                    db.BookingTransactionCreditCards.Where(p => p.BookingId == bookingId && p.OrderDateTime == null).ForEach(item => db.BookingTransactionCreditCards.DeleteObject(item));

                    db.Bookings.ApplyChanges(booking);
                    db.SaveChanges();

                    booking = GetBooking2(db, bookingId);
                    return new BookingResponse { Booking = booking };
                }
            }
            catch (Exception ex)
            {
                var response = new BookingResponse();
                response.AddError("Response", ex.ToString());
                return response;
            }
        }
Exemplo n.º 2
0
        public BookingResponse SaveBookingPickUpTimeDropOffTimeAndPromoCode(int bookingId, DateTime pickUptime, DateTime? dropOffTime, string promoCode)
        {
            DebugWriter debugInfoWriter = new DebugWriter();

            try
            {
                using (var db = new LomsContext())
                {
                    var booking = db.Bookings.IncludeAll("FareInfo", "FareInfo.Items").FirstOrDefault(b => b.Id == bookingId);

                    if (booking.PickUpTime != pickUptime)
                    {
                        booking.PickUpTime = pickUptime;
                        booking.OnPickUpTimeChanged();
                    }
                    if (booking.DropOffTime != dropOffTime)
                    {
                        booking.DropOffTime = dropOffTime;
                        booking.OnDropOffTimeChanged();
                    }
                    if (booking.PromoCode != promoCode)
                    {
                        booking.PromoCode = promoCode;
                        booking.OnPromoCodeChanged();
                    }

                    db.Bookings.ApplyChanges(booking);
                    db.SaveChanges();

                    booking = GetBooking(db, booking.Id);
                    return new BookingResponse { Booking = booking, DebugInfo = debugInfoWriter.ToString() };
                }
            }
            catch (Exception ex)
            {
                var response = new BookingResponse() { DebugInfo = debugInfoWriter.ToString() };
                response.AddError("Response", ex.ToString());
                return response;
            }
        }
Exemplo n.º 3
0
        public BookingResponse GetBookingWithFareInfo(int bookingId)
        {
            DebugWriter debugInfoWriter = new DebugWriter();

            try
            {
                DateTime utc = DateTime.UtcNow;
                using (var db = new LomsContext())
                {
                    var booking = GetBooking(db, bookingId);

                    if (!booking.CreatorId.HasValue)
                    {
                        booking.CreatorId = CurrentUserId();
                        booking.PrimaryPassengerId = CurrentUserId();
                    }

                    //generate fares
                    if (booking.Status == BookingStatus.InProgress)
                    {
                        if (booking.FareInfo == null)
                            booking.FareInfo = new BookingFareInfo() { BookingId = booking.Id };

                        //vehicle availability
                        if (VehicleAvailabilityHelper.AllocateVehicle(db, booking, true, debugInfoWriter.GetStringBuilder()))  //phantom
                        {
                            booking.Status = BookingStatus.Fare;
                            FillBookingWithFareInfo(db, booking, debugInfoWriter);
                            if (booking.FareInfo.Price == 0)
                                booking.Status = BookingStatus.Pending;
                            utc = DateTime.UtcNow;
                            booking.ExpiryTime = utc.AddMinutes(10.0);
                        }
                        else if (VehicleAvailabilityHelper.AllocateVehicle(db, booking, false, debugInfoWriter.GetStringBuilder())) //pending
                        {
                            booking.Status = BookingStatus.Pending;
                            FillBookingWithFareInfo(db, booking, debugInfoWriter);
                            utc = DateTime.UtcNow;
                            booking.ExpiryTime = utc.AddMinutes(10.0);
                        }
                        else
                        {
                            booking.Status = BookingStatus.NoAvailability;
                            booking.ExpiryTime = null;
                        }
                    }

                    db.Bookings.ApplyChanges(booking);
                    db.SaveChanges();

                    booking = GetBooking(db, booking.Id);
                    return new BookingResponse { Booking = booking, DebugInfo = debugInfoWriter.ToString(), ServerUtcTime = utc };
                }
            }
            catch (Exception ex)
            {
                var response = new BookingResponse() { DebugInfo = debugInfoWriter.ToString() };
                response.AddError("Response", ex.ToString());
                return response;
            }
        }
Exemplo n.º 4
0
        public BookingResponse SaveBookingVehicleType(int bookingId, int vehicleTypeId)
        {
            try
            {
                using (var db = new LomsContext())
                {
                    var booking = GetBooking(db, bookingId);

                    if (booking.VehicleTypeId != vehicleTypeId)
                    {
                        booking.VehicleTypeId = vehicleTypeId;
                        booking.OnVehicleTypeChanged();

                        db.Bookings.ApplyChanges(booking);
                        db.SaveChanges();
                    }

                    booking = GetBooking(db, booking.Id);
                    return new BookingResponse { Booking = booking };
                }
            }
            catch (Exception ex)
            {
                var response = new BookingResponse();
                response.AddError("Response", ex.ToString());
                return response;
            }
        }
Exemplo n.º 5
0
        public BookingResponse SaveBookingStops(int bookingId, IEnumerable<BookingStop> stops)
        {
            try
            {
                using (var db = new LomsContext())
                {
                    var booking = GetBooking(db, bookingId);

                    //remove
                    foreach (var stop in booking.Stops)
                        if (!stops.Any(s => s.Id == stop.Id))
                            stop.MarkAsDeleted();

                    //add
                    stops.Where(s => s.Id == 0)
                        .ForEach(s =>
                        {
                            s.ClearPropertiesButSkipKeys();
                            var newStop = new BookingStop();
                            newStop.SetDataFrom(s);
                            booking.Stops.Add(newStop);
                        });


                    //update
                    stops.Where(s => s.Id != 0).ForEach(s => booking.Stops.First(bs => bs.Id == s.Id).SetDataFrom(s));

                    db.Bookings.ApplyChanges(booking);
                    db.SaveChanges();

                    booking = GetBooking(db, booking.Id);
                    return new BookingResponse { Booking = booking };
                }
            }
            catch (Exception ex)
            {
                var response = new BookingResponse();
                response.AddError("Response", ex.ToString());
                return response;
            }
        }
Exemplo n.º 6
0
        public BookingResponse SaveBookingDropOffEndpoint(int bookingId, BookingEndpoint endpoint)
        {
            try
            {
                using (var db = new LomsContext())
                {
                    var booking = GetBooking(db, bookingId);

                    if (booking.DropOffEndpoint.Type != endpoint.Type ||
                        booking.DropOffEndpoint.Address1 != endpoint.Address1 ||
                        booking.DropOffEndpoint.SuburbId != endpoint.SuburbId ||
                        booking.DropOffEndpoint.AirportId != endpoint.AirportId)
                    {
                        booking.OnDropOffEndpointChanged();
                    }

                    booking.DropOffEndpoint.SetDataFrom(endpoint);

                    //airport default city
                    if (booking.JourneyType == JourneyType.ToAirport)
                        if (booking.DropOffEndpoint.Type == BookingEndpointType.AirportOther || booking.DropOffEndpoint.Type == BookingEndpointType.AirportPrivate)
                        {
                            var airportDefaultCity = db.AirportCities.SingleOrDefault(a => a.AirportId == booking.DropOffEndpoint.AirportId && a.IsDefault);
                            if (airportDefaultCity != null && booking.CityId != airportDefaultCity.CityId)
                                booking.CityId = airportDefaultCity.CityId;
                        }

                    db.Bookings.ApplyChanges(booking);
                    db.SaveChanges();

                    booking = GetBooking(db, bookingId);
                    return new BookingResponse { Booking = booking };
                }
            }
            catch (Exception ex)
            {
                var response = new BookingResponse();
                response.AddError("Response", ex.ToString());
                return response;
            }
        }
Exemplo n.º 7
0
        public BookingResponse SaveBookingJourneyType(int bookingId, JourneyType journeyType)
        {
            try
            {
                using (var db = new LomsContext())
                {
                    var booking = GetBooking(db, bookingId);
                    if (booking.JourneyType != journeyType)
                    {
                        booking.JourneyType = journeyType;
                        booking.OnJourneyTypeChanged();

                        db.Bookings.ApplyChanges(booking);
                        db.SaveChanges();
                    }

                    booking = GetBooking(db, booking.Id);
                    return new BookingResponse { Booking = booking };
                }
            }
            catch (Exception ex)
            {
                var response = new BookingResponse();
                response.AddError("Response", ex.ToString());
                return response;
            }
        }
Exemplo n.º 8
0
        public BookingResponse CreateBooking(CreateBookingRequest request)
        {
            try
            {
                using (var db = new LomsContext())
                {
                    var pickUpEndpoint = new BookingEndpoint();
                    var dropOffEndpoint = new BookingEndpoint();
                    db.BookingEndpoints.ApplyChanges(pickUpEndpoint);
                    db.BookingEndpoints.ApplyChanges(dropOffEndpoint);
                    db.SaveChanges();

                    var booking = new Booking()
                    {
                        Status = BookingStatus.New,
                        CityId = request.CityId,
                        CreatorId = request.CreatorId,
                        PrimaryPassengerId = request.PrimaryPassengerId,
                        PickUpEndpointId = pickUpEndpoint.Id,
                        DropOffEndpointId = dropOffEndpoint.Id
                    };

                    db.Bookings.ApplyChanges(booking);
                    db.SaveChanges();

                    booking = GetBooking(db, booking.Id);
                    return new BookingResponse { Booking = booking };
                }
            }
            catch (Exception ex)
            {
                var response = new BookingResponse();
                response.AddError("Response", ex.ToString());
                return response;
            }
        }