Exemple #1
0
     private void FixupChargeInfo(BookingChargeInfo previousValue)
     {
         // This is the principal end in an association that performs cascade deletes.
         // Update the event listener to refer to the new dependent.
         if (previousValue != null)
         {
             ChangeTracker.ObjectStateChanging -= previousValue.HandleCascadeDelete;
         }
 
         if (ChargeInfo != null)
         {
             ChangeTracker.ObjectStateChanging += ChargeInfo.HandleCascadeDelete;
         }
 
         if (IsDeserializing)
         {
             return;
         }
 
         if (ChargeInfo != null)
         {
             ChargeInfo.BookingId = Id;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("ChargeInfo")
                 && (ChangeTracker.OriginalValues["ChargeInfo"] == ChargeInfo))
             {
                 ChangeTracker.OriginalValues.Remove("ChargeInfo");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("ChargeInfo", previousValue);
                 // This is the principal end of an identifying association, so the dependent must be deleted when the relationship is removed.
                 // If the current state of the dependent is Added, the relationship can be changed without causing the dependent to be deleted.
                 if (previousValue != null && previousValue.ChangeTracker.State != ObjectState.Added)
                 {
                     previousValue.MarkAsDeleted();
                 }
             }
             if (ChargeInfo != null && !ChargeInfo.ChangeTracker.ChangeTrackingEnabled)
             {
                 ChargeInfo.StartTracking();
             }
         }
     }
Exemple #2
0
        Booking GetBookingWithChargeInfo(LomsContext db, int bookingId)
        {
            var bookingChildren = new[]
            {
                "City",
                "FareInfo", "FareInfo.Currency", "FareInfo.Items",
                "PassengerInfo","PassengerInfo.Adults","PassengerInfo.Childs","PassengerInfo.Infants",
                "ProvisionInfo",
                "ChargeInfo", "ChargeInfo.Items",
                "TransactionCreditCards", "TransactionCreditCards.Info"
            };

            var booking = db.Bookings.IncludeAll(bookingChildren).SingleOrDefault(b => b.Id == bookingId);

            if (booking.ChargeInfo != null)
                return booking;

            var chargeInfo = new BookingChargeInfo() { BookingId = bookingId };
            db.BookingChargeInfoes.ApplyChanges(chargeInfo);
            db.SaveChanges();

            decimal amount = 0;

            var fare = booking.FareInfo.Items.Single(f => f.FareType == booking.FareType);
            if (!string.IsNullOrWhiteSpace(booking.PromoCode))
                db.BookingChargeInfoItems.ApplyChanges(new BookingChargeInfoItem() { BookingId = bookingId, Name = string.Format("FARE TYPE {1} (LESS PROMO CODE)", booking.FareType, fare.Name), Amount = fare.Price });
            else
                db.BookingChargeInfoItems.ApplyChanges(new BookingChargeInfoItem() { BookingId = bookingId, Name = string.Format("FARE TYPE {1}", booking.FareType, fare.Name), Amount = fare.Price });
            amount = fare.Price;

            int i = 1;
            foreach (var child in booking.PassengerInfo.Childs)
                if (child.BabySeat == (byte)ChildSeatSupplierForBooking.DriverToSupply)
                {
                    decimal itemAmount = (decimal)booking.City.ChildRestraint3;
                    if (i == 1) itemAmount = (decimal)booking.City.ChildRestraint1;
                    else if (i == 2) itemAmount = (decimal)booking.City.ChildRestraint2;
                    db.BookingChargeInfoItems.ApplyChanges(new BookingChargeInfoItem() { BookingId = bookingId, Name = "CHILD SEAT " + i++, Amount = itemAmount });
                    amount += itemAmount;
                }
            foreach (var infant in booking.PassengerInfo.Infants)
                if (infant.BabySeat == (byte)ChildSeatSupplierForBooking.DriverToSupply)
                {
                    decimal itemAmount = (decimal)booking.City.ChildRestraint3;
                    if (i == 1) itemAmount = (decimal)booking.City.ChildRestraint1;
                    else if (i == 2) itemAmount = (decimal)booking.City.ChildRestraint2;

                    db.BookingChargeInfoItems.ApplyChanges(new BookingChargeInfoItem() { BookingId = bookingId, Name = "CHILD SEAT " + i++, Amount = itemAmount });
                    amount += itemAmount;
                }

            if (booking.ProvisionInfo.WaitingTime > 0)
            {
                decimal itemAmount = booking.City.Round(booking.ProvisionInfo.WaitingTime * booking.ProvisionInfo.ApprovedWaitingTimeRate / 60.0m);

                string name;
                if (booking.ProvisionInfo.WaitingTime < 60)
                    name = string.Format("PRE-PURCHASED WAITING TIME ({0} MINUTES)", booking.ProvisionInfo.WaitingTime);
                else if (booking.ProvisionInfo.WaitingTime == 60)
                    name = string.Format("PRE-PURCHASED WAITING TIME (1 HOUR)", booking.ProvisionInfo.WaitingTime);
                else if (booking.ProvisionInfo.WaitingTime < 120)
                    name = string.Format("PRE-PURCHASED WAITING TIME (1 HOUR {0} MINUTES)", booking.ProvisionInfo.WaitingTime % 60);
                else //(CurrentBooking.ProvisionInfo.WaitingTime > 120)
                    name = string.Format("PRE-PURCHASED WAITING TIME ({0} HOUR {1} MINUTES)", booking.ProvisionInfo.WaitingTime / 60, booking.ProvisionInfo.WaitingTime % 60);

                db.BookingChargeInfoItems.ApplyChanges(new BookingChargeInfoItem() { BookingId = bookingId, Name = name, Amount = itemAmount });
                amount += itemAmount;
            }
            //db.BookingChargeInfoItems.ApplyChanges(new BookingChargeInfoItem() { BookingId = bookingId, Name = "Total Charges AU$", Amount = amount });

            chargeInfo.Amount = amount;
            db.BookingChargeInfoes.ApplyChanges(chargeInfo);
            db.SaveChanges();

            booking.ChargeInfo = chargeInfo;
            booking.MarkAsUnchanged();

            return booking;
        }
     public bool Equals(BookingChargeInfo other)
     {
         if (ReferenceEquals(null, other)) return false;
         if (ReferenceEquals(this, other)) return true;
 		if (other.BookingId == 0 && BookingId == 0)
 			return false;
 		else
 			return other.BookingId == BookingId;
     }