/// <summary>
        /// Returns false only if all fields for the range has availability set to false
        /// </summary>
        /// <remarks>
        /// This method is useful to checking un-availability, as it will return true if there is any availability in a date range
        /// </remarks>        
        /// <param name="availability">The record to check</param>
        /// <param name="fromDayOfYear">From which Day Of Year</param>
        /// <param name="toDayOfYear">OPTIONAL: to which Day Of Year, last day in sequence will not be checked will not be checked</param>
        /// <returns>True if any of the rooms in the range specified is available otherwise false</returns>
        public static bool AreAnyRoomsInRangeAvailable(RoomsAvailability availability, int fromDayOfYear, int? toDayOfYear = null)
        {
            // if the availability is null means that the room is assumed to be available 
            if(availability == null)
            {
                return true;
            }

            //because we have leap years we need to consider either 365 or 366 days
            if (!toDayOfYear.HasValue)
            {
                GregorianCalendar calendar = new GregorianCalendar();
                toDayOfYear = calendar.GetDaysInYear(availability.Year);
            }

            bool isAvailable = false;
            for (int d = fromDayOfYear; d < toDayOfYear; d++)
            {
                string propertyName = String.Format("IsDay{0:000}Available", d);
                PropertyInfo p = typeof(RoomsAvailability).GetProperty(propertyName);

                isAvailable = isAvailable | (bool)p.GetValue(availability, null);
            }
            return isAvailable;
        }
        /// <summary>
        /// Returns false only if all fields for the range has availability set to false
        /// </summary>
        /// <param name="availability1">And RoomsAvailability to compare</param>
        /// <param name="availability2">And RoomsAvailability to compare</param>
        /// <returns>True if availability is the same for both records</returns>
        public static bool IsAvailabilityTheSame(RoomsAvailability availability1, RoomsAvailability availability2)
        {
            // Some basic checks
            if (availability1 == null & availability2 == null)
            {
                // Implies both sets are available
                return true;
            }            
            if (availability1 == null || availability2 == null)
            {
                return false;
            }

            int fromDayOfYear = 1;
            int toDayOfYear = 366;

            bool isEqual = true;
            for (int d = fromDayOfYear; d < toDayOfYear; d++)
            {
                string propertyName = String.Format("IsDay{0:000}Available", d);
                PropertyInfo p = typeof(RoomsAvailability).GetProperty(propertyName);

                isEqual = isEqual & ((bool)p.GetValue(availability1, null)).Equals((bool)p.GetValue(availability2, null));
            }
            return isEqual;
        }
        /// <summary>
        /// Map the basic fields for the RoomsAvailability table to the RoomsAvailability model object
        /// </summary>
        /// <param name="record">The SqlDataReader with the executed query result</param>
        /// <param name="prefix">a prefix used to identify fields for the RoomsAvailability model  in the resultset if required</param>        
        /// <returns>An instance of Model.Room.RoomsAvailability</returns>
        internal static RoomsAvailability MapRecord(IDataRecord record, string prefix = "")
        {
            var roomsAvailability = new RoomsAvailability
            {
                BusinessId = DbHelper.ConvertValue<long>(record[prefix + Parameters.BusinessId]),
                RoomTypeId = DbHelper.ConvertValue<int>(record[prefix + Parameters.RoomTypeId]),
                BaseRatePlanId = DbHelper.ConvertValue<int>(record[prefix + Parameters.BaseRatePlanId]),
                RatePlanId = DbHelper.ConvertValue<int>(record[prefix + Parameters.RatePlanId]),
                MaxAdults = DbHelper.ConvertValue<byte>(record[prefix + Parameters.MaxAdults]),
                MaxChildren = DbHelper.ConvertValue<byte>(record[prefix + Parameters.MaxChildren]),
                MaxOccupancy = DbHelper.ConvertValue<byte>(record[prefix + Parameters.MaxOccupancy]),
                MinStay = DbHelper.ConvertValue<byte>(record[prefix + Parameters.MinStay]),
                BoardBasis = new BoardBasis { Code = DbHelper.ConvertValue<string>(record[prefix + Parameters.BoardBasisCode]) },
                CancellationClass = new CancellationClass { Code = DbHelper.ConvertValue<string>(record[prefix + Parameters.CancellationClassCode]) },
                TotalRate = DbHelper.ConvertValue<decimal>(record[prefix + Parameters.Rate], nullReplace: default(decimal)),
                TotalWasRate = DbHelper.ConvertValue<decimal?>(record[prefix + Parameters.WasRate]),
                Available = DbHelper.ConvertValue<byte>(record[prefix + Parameters.Available]),
                RatePlanName = DbHelper.ConvertValue<string>(record[prefix + Parameters.RatePlanName]),
                DisplayName = DbHelper.ConvertValue<string>(record[prefix + Parameters.DisplayName]),
                PrePayType = DbHelper.ConvertEnumValue<PrePayRuleTypeEnum>(record[prefix + Parameters.PrePayRuleTypeCode]),
                PrePayRuleValue = DbHelper.ConvertValue<decimal?>(record[prefix + Parameters.PrePayRuleValue])
            };

            var unavailabilityList = DbHelper.ConvertValue<string>(record[prefix + Parameters.NoAvailabilityCode]);

            if (string.IsNullOrWhiteSpace(unavailabilityList) == false)
            {
                roomsAvailability.UnavailabilityReason =
                    DbHelper.ConvertEnumValue<UnavailabilityReasonCode>(unavailabilityList.Split(',')[0]);
            }

            if (roomsAvailability.UnavailabilityReason == UnavailabilityReasonCode.Unknown)
            {
                roomsAvailability.UnavailabilityReason = null;
            }

            // if we have a room list then we will have a corresponding room name list
            if (record.HasColumn(Parameters.RoomList.ToString()))
            {
                var roomList = DbHelper.ConvertValue<string>(record[prefix + Parameters.RoomList]);
                var roomNameList = DbHelper.ConvertValue<string>(record[prefix + Parameters.RoomNameList]);

                // only split and convert if not an empty string
                if (string.IsNullOrWhiteSpace(roomList) == false)
                {
                    roomsAvailability.RoomList = roomList.Split(',').ToList().ConvertAll(int.Parse);
                    roomsAvailability.RoomNameList = roomNameList.Split(',').ToList();
                }
            }

            return roomsAvailability;
        }
Exemple #4
0
 /// <summary>
 /// Checks if the rate plan for this is same as base other than MLOS
 /// </summary>
 /// <param name="otherRoomsAvailability">rooms availability to compare to</param>
 /// <returns>true if they match</returns>
 public bool IsSameOtherThanMlos(RoomsAvailability otherRoomsAvailability)
 {
     return otherRoomsAvailability != null &&
            otherRoomsAvailability.RoomTypeId == this.RoomTypeId &&
            otherRoomsAvailability.MaxAdults == this.MaxAdults &&
            otherRoomsAvailability.MaxChildren == this.MaxChildren &&
            otherRoomsAvailability.MaxOccupancy == this.MaxOccupancy &&
            ((otherRoomsAvailability.Currency == null &&
            this.Currency == null) ||
            (otherRoomsAvailability.Currency != null &&
            this.Currency != null &&
            otherRoomsAvailability.Currency.ISOCode == this.Currency.ISOCode)) &&
            ((otherRoomsAvailability.BoardBasis == null &&
            this.BoardBasis == null) ||
            (otherRoomsAvailability.BoardBasis != null &&
            this.BoardBasis != null &&
            otherRoomsAvailability.BoardBasis.Code == this.BoardBasis.Code)) &&
            ((otherRoomsAvailability.CancellationClass == null &&
            this.CancellationClass == null) ||
            (otherRoomsAvailability.CancellationClass != null &&
            this.CancellationClass != null &&
            otherRoomsAvailability.CancellationClass.Code == this.CancellationClass.Code));
 }
            public void DoExchangeRateConversionDoesNotSetUnavailableOnExceptionWhenAlreadyUnavailable()
            {
                var fxManager = new Mock<IFxManager>();
                var availableRoom = new RoomsAvailability
                {
                    TotalWasRate = 50M,
                    TotalRate = 40M,
                    BusinessId = BUSINESS_ONE,
                    UnavailabilityReason = UnavailabilityReasonCode.MaxAdultExceeded
                };
                fxManager.Setup(
                    fx =>
                    fx.ConvertMoney(
                        It.Is<Money>(m => m.Amount == availableRoom.TotalRate && m.Currency == CURRENCY_ONE),
                        CURRENCY_TWO, BUSINESS_ONE)).Throws(new Exception());

                availabilityManager.FxManager = fxManager.Object;

                availabilityManager.DoExchangeRateConversion(availableRoom, CURRENCY_ONE, CURRENCY_TWO);

                Assert.AreEqual(UnavailabilityReasonCode.MaxAdultExceeded, availableRoom.UnavailabilityReason, "incorrect unavailability reason set");
                fxManager.VerifyAll();
            }
            public void DoExchangeRateConversionCallsCorrectMethods()
            {
                var fxManager = new Mock<IFxManager>();
                var availableRoom = new RoomsAvailability
                    {
                        TotalWasRate = 50M,
                        TotalRate = 40M,
                        BusinessId = BUSINESS_ONE
                    };
                fxManager.Setup(
                    fx =>
                    fx.ConvertMoney(
                        It.Is<Money>(m => m.Amount == availableRoom.TotalRate && m.Currency == CURRENCY_ONE),
                        CURRENCY_TWO, BUSINESS_ONE)).Returns(new Money(afterConversionOne, CURRENCY_TWO));

                fxManager.Setup(
                    fx =>
                    fx.ConvertMoney(
                        It.Is<Money>(m => m.Amount == availableRoom.TotalWasRate && m.Currency == CURRENCY_ONE),
                        CURRENCY_TWO, BUSINESS_ONE)).Returns(new Money(afterConversionTwo, CURRENCY_TWO));

                availabilityManager.FxManager = fxManager.Object;

                availabilityManager.DoExchangeRateConversion(availableRoom, CURRENCY_ONE, CURRENCY_TWO);

                Assert.AreEqual(afterConversionOne, availableRoom.TotalRate, "incorrect amount set for total");
                Assert.AreEqual(afterConversionTwo, availableRoom.TotalWasRate, "incorrect amount set for total was");
                Assert.AreEqual(CURRENCY_TWO, availableRoom.CurrencyCode, "incorrect currency set");

                fxManager.VerifyAll();
            }
 /// <summary>
 /// test data constructor
 /// </summary>
 /// <param name="baseAvailable">base rooms availability rate plan data</param>
 /// <param name="variantAvailable">variant rooms availability rate plan data</param>
 /// <param name="expectedWasRate">expected value for was rate on variant</param>
 public TestData(RoomsAvailability baseAvailable, RoomsAvailability variantAvailable,
                 decimal expectedWasRate)
 {
     this.baseRoomsAvailability = baseAvailable;
     this.expectedVariantWasRate = expectedWasRate;
     this.variantRoomsAvailability = variantAvailable;
 }
Exemple #8
0
 /// <summary>
 /// Update the room type name with value from cache
 /// </summary>
 /// <param name="room">Room to update</param>
 private void SetRoomTypeName(RoomsAvailability room)
 {
     var roomType = Cache.Cache.RoomType.GetValue(room.RoomTypeId);
     if (roomType != null)
     {
         room.RoomTypeName = roomType.Name;
     }            
 }
Exemple #9
0
        /// <summary>
        /// Update the available room given by changing the rate / wasrate from currency to currency
        /// </summary>
        /// <param name="availableRoom">available room from search results</param>
        /// <param name="fromCurrencyCode">currency code A</param>
        /// <param name="requestedCurrency">currency code B</param>
        public virtual void DoExchangeRateConversion(RoomsAvailability availableRoom, string fromCurrencyCode, string requestedCurrency)
        {
            Logger.LogInfo("DoExchangeRateConversion called from {0} to {1}", args: new object[]{fromCurrencyCode, requestedCurrency});
            Logger.LogDebugAsXml(availableRoom);
            var businessCache = Cache.Cache.Business.GetValue(availableRoom.BusinessId);
            if (businessCache.ContractCurrencyCode.Equals(requestedCurrency))
            {
                try
                {
                    var amount =
                        FxManager.ConvertMoney(
                            new Money(availableRoom.TotalRate, fromCurrencyCode),
                            requestedCurrency, availableRoom.BusinessId);
                    var wasAmount =
                        FxManager.ConvertMoney(
                            new Money(availableRoom.TotalWasRate.HasValue ? availableRoom.TotalWasRate.Value : availableRoom.TotalRate, fromCurrencyCode),
                            requestedCurrency, availableRoom.BusinessId);

                    Logger.LogDebug("Source {0} in currency {1} converted to {2} in currency {3}", args: new object[] { availableRoom.TotalRate, fromCurrencyCode, amount.Amount, amount.Currency });

                    availableRoom.TotalRate = amount.Amount;
                    availableRoom.CurrencyCode = amount.Currency;
                    availableRoom.TotalWasRate = wasAmount.Amount;
                }
                catch
                {
                    // only set if not already unavailable
                    if (!availableRoom.UnavailabilityReason.HasValue)
                    {
                        availableRoom.UnavailabilityReason =
                            UnavailabilityReasonCode.MissingExchangeRates;
                    }
                }
            }
            else
            {
                Logger.LogInfo("Requested Currency {0} did not match Contract Currency {1}", args: new object[]{requestedCurrency, businessCache.ContractCurrencyCode});
                availableRoom.CurrencyCode = fromCurrencyCode;
                availableRoom.Currency = Cache.Cache.CurrencyCache.GetValue("root").Get(fromCurrencyCode);
            }
        }