Example #1
0
        /// <summary>
        /// Modify a room type and its base rate plan
        /// </summary>
        /// <param name="roomType">The room type object to modify</param>
        public void ModifyRoomTypeAndBaseRatePlan(RoomType roomType)
        {
            // Validate data
            if (roomTypeDao.DoesRoomTypeExist(roomType))
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30093, "RoomManager.ModifyRoomTypeAndBaseRatePlan", arguments: new object[] { roomType }));
            }

            using (var btx = new BusinessTransaction())
            {
                var baseRatePlan = roomType.BaseRatePlan;

                if (roomType.IsValid() && baseRatePlan.IsValid())
                {
                    // Modify room type and subsequent business event
                    roomTypeDao.Modify(roomType);

                    baseRatePlan.RoomTypeId = roomType.Id;

                    // Modify rate plan
                    ratePlanManager.ModifyBaseRatePlan(baseRatePlan);

                    btx.Commit();

                    eventTrackingManager.CreateBusinessEventAsync(roomType.BusinessId,
                                                             BusinessEventTypesEnum.RoomTypeModified,
                                                             roomType.Id.ToString(CultureInfo.InvariantCulture));
                }
            }

            // Invalid this item in the cache so it is retrieved again
            // Needs to be after transaction so updated info is in db and readable.
            Cache.Cache.RoomType.Invalidate(roomType.Id);
            Cache.Cache.RatePlanViewCache.Invalidate(roomType.BusinessId);
            Cache.Cache.PromoCache.Invalidate(roomType.BusinessId);
        }
Example #2
0
        /// <summary>
        /// Create a record for room type and its base rate plan
        /// </summary>
        /// <param name="roomType">The room type object to create</param>
        public void CreateRoomTypeAndBaseRatePlan(RoomType roomType)
        {
            using (var btx = new BusinessTransaction())
            {
                // determine if room type exists and is active
                bool activeRoomTypeExists = roomTypeDao.DoesRoomTypeExist(roomType);

                // if room type exists and is active, throw validation exception
                if (activeRoomTypeExists)
                {
                    throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30093, "RoomManager.CreateRoomTypeAndBaseRatePlan", arguments: new object[] { roomType }));
                }

                RoomType roomTypeReference = roomTypeDao.GetByRoomTypeInformation(roomType);

                //  if room type exists and is not active, activate it
                if (roomTypeReference != null)
                {
                    //set room type isActive flag to true
                    roomTypeDao.ActivateRoomType(roomTypeReference.Id);

                    // set rooms belonging to room type to active
                    List<Model.Room.Room> rooms = roomManager.GetRoomsByBusinessRoomType(roomTypeReference.Id, roomTypeReference.BusinessId);

                    // createRoom method detects existing rooms and set it to active
                    rooms.ForEach(r => roomManager.CreateRoom(r.Name, r.RoomTypeId, r.BusinessId));

                    roomType.Id = roomTypeReference.Id;

                    BaseRatePlan inputBaseRatePlan = roomType.BaseRatePlan;
                    BaseRatePlan roomTypeBaseRatePlan = baseRatePlanDao.GetByRoomTypeId(roomTypeReference.Id, roomTypeReference.BusinessId);

                    if (roomTypeBaseRatePlan == null)
                    {
                        throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30062,
                                                                                     "RoomManager.CreateRoomTypeAndBaseRatePlan",
                                                                                     arguments: new object[] { roomType }));
                    }

                    if (inputBaseRatePlan == null)
                    {
                        throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30062,
                                                                                     "RoomManager.CreateRoomTypeAndBaseRatePlan",
                                                                                     arguments: new object[] { roomType }));
                    }

                    roomTypeBaseRatePlan.RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base };
                    roomTypeBaseRatePlan.RoomTypeId = roomTypeReference.Id;
                    roomTypeBaseRatePlan.BusinessId = roomTypeReference.BusinessId;
                    roomTypeBaseRatePlan.RackRate = inputBaseRatePlan.RackRate;
                    roomTypeBaseRatePlan.MaxAdults = inputBaseRatePlan.MaxAdults;
                    roomTypeBaseRatePlan.MaxChildren = inputBaseRatePlan.MaxChildren;
                    roomTypeBaseRatePlan.MaxOccupancy = inputBaseRatePlan.MaxOccupancy;
                    roomTypeBaseRatePlan.BoardBasis = inputBaseRatePlan.BoardBasis;
                    roomTypeBaseRatePlan.CancellationClass = inputBaseRatePlan.CancellationClass;
                    roomTypeBaseRatePlan.SellAtRackRate = inputBaseRatePlan.SellAtRackRate;
                    roomTypeBaseRatePlan.UseOccupancyRates = inputBaseRatePlan.UseOccupancyRates;
                    roomTypeBaseRatePlan.DisplayName = inputBaseRatePlan.DisplayName;

                    ratePlanManager.ModifyBaseRatePlan(roomTypeBaseRatePlan);
                    
                    btx.Commit();

                    // set event for activation of room type
                    eventTrackingManager.CreateBusinessEventAsync(roomTypeReference.BusinessId,
                                                             BusinessEventTypesEnum.RoomTypeActivated,
                                                             roomTypeReference.Id.ToString(), null);
                }
                else
                {
                    BaseRatePlan baseRatePlan = roomType.BaseRatePlan;

                    if (baseRatePlan == null)
                    {
                        throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30062,
                                                                                     "RoomManager.CreateRoomTypeAndBaseRatePlan",
                                                                                     arguments: new object[] { roomType }));
                    }

                    // NOTE: ServiceFrequency isn't currently implemented so are hard coded here for the time being
                    roomType.ServiceFrequency = new EnumEntity { Code = ServiceFrequencyEnum.Daily.GetCode() };

                    baseRatePlan.RatePlanType = new RatePlanType { Type = RatePlanTypeEnum.Base };

                    if (roomType.IsValid() && baseRatePlan.IsValid())
                    {
                        // Create room type and subsequent business event
                        roomTypeDao.Create(roomType);

                        // Create rate plan and subsequent business event
                        baseRatePlan.RoomTypeId = roomType.Id;
                        baseRatePlanDao.Create(baseRatePlan);

                        btx.Commit();

                        eventTrackingManager.CreateBusinessEventAsync(roomType.BusinessId,
                                                                 BusinessEventTypesEnum.RoomTypeAdded,
                                                                 roomType.Id.ToString(CultureInfo.InvariantCulture));

                        eventTrackingManager.CreateBusinessEventAsync(roomType.BusinessId,
                                                                 BusinessEventTypesEnum.RatePlanAdded,
                                                                 baseRatePlan.Id.ToString(CultureInfo.InvariantCulture));
                    }
                }
            }

            // Invalidate the cache so it refreshes
            Cache.Cache.RatePlanViewCache.Invalidate(roomType.BusinessId);
        }