Example #1
0
        /// <summary>
        /// Modify Room
        /// </summary>
        /// <param name="room">Room</param>
        public void Modify(Model.Room.Room room)
        {
            if (room == null || room.IsValid() == false)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30068, "RoomManager.Modify", arguments: new object[] { this }));
            }

            Model.Room.Room existingRoom = roomDao.GetByName(room.Name, room.BusinessId);
            if (existingRoom != null && existingRoom.Id != room.Id)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30085, "RoomManager.Modify",
                                                                             additionalDescriptionParameters: (new object[] { room.BusinessId })));
            }

            var bookings = bookingManager.GetByRoom(room.Id).AsQueryable().Where(b => b.StartDate >= DateTime.UtcNow || b.EndDate >= DateTime.UtcNow);

            // If any were found throw validation exception if trying to change status
            if (bookings.Any() && room.RoomStatusCode != RoomStatusCodes.ACTIVE)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30097, "RoomManager.Modify", arguments: new object[] { this }));
            }

            using (var businessTransaction = new BusinessTransaction())
            {
                roomDao.Modify(room);

                businessTransaction.Commit();
            }

            eventTrackingManager.CreateBusinessEventAsync(room.BusinessId,
                                                              BusinessEventTypesEnum.RoomModified,
                                                              room.Id.ToString(CultureInfo.InvariantCulture));
        }
Example #2
0
        /// <summary>
        /// Create User
        /// </summary>
        /// <remarks>
        /// The user to create will have a default password associated in the initial stage. 
        /// Things like password and security question and security password should be created at
        ///  a later stage during the activation process
        /// </remarks>
        /// <param name="user">User to create</param>
        /// <returns>Guid of the created user</returns>
        public Guid Create(Model.User.User user)
        {

            var newUserId = Guid.Empty;

            if (!user.IsValid())
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30052, "UserManager.create"));
            }

            MembershipCreateStatus createStatus;

            MembershipUser newUser = Membership.CreateUser(user.UserName, DefaultPassword, user.UserName,
                                                           DefaultPasswordQuestion, DefaultPasswordAnswer, true,
                                                           out createStatus);

            if (createStatus != MembershipCreateStatus.Success)
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30053, "Membership.CreateUser"));
            }

            if (newUser != null && newUser.ProviderUserKey != null)
            {
                var newUserIdentifier = (Guid)newUser.ProviderUserKey;
                userExtensionDao.Create(new UserExtension
                {
                    UserId = newUserIdentifier,
                    FirstName = user.Extension.FirstName,
                    LastName = user.Extension.LastName,
                    CultureCode = user.Extension.CultureCode
                });
                RecordUserEvent(user.UserName, UserEventTypesEnum.UserCreated);
                newUserId = newUserIdentifier;
            }

            return newUserId;

        }
Example #3
0
        /// <summary>
        /// Modify User
        /// </summary>
        /// <param name="user">User</param>
        public void Modify(Model.User.User user)
        {
            if (!user.IsValid())
            {
                throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30051, "UserManager.Modify"));
            }

            using (var btx = new BusinessTransaction())
            {
                userDao.Modify(user);

                // Update UserExtension
                userExtensionDao.Modify(user.Extension);

                //make sure to update the membership with the new user name used
                var membershipUser = Membership.GetUser(user.Id);
                if (membershipUser != null)
                {
                    membershipUser.Email = user.UserName;
                    Membership.UpdateUser(membershipUser);
                }

                RecordUserEvent(user.UserName, UserEventTypesEnum.UserModified);
                btx.Commit();
            }
        }
Example #4
0
        /// <summary>
        /// Search availability using online business logic
        /// </summary>
        /// <param name="onlineAvailabilitySearchCriteria">search criteria to use</param>
        /// <returns>Available rooms found</returns>
        public AvailabilitySearchResult CheckOnlineAvailability(Model.Room.Online.AvailabilitySearchCriteria onlineAvailabilitySearchCriteria)
        {
            Logger.LogInfo("==========CheckOnlineAvailability Called==========");
            Logger.LogDebugAsXml(onlineAvailabilitySearchCriteria);
            AvailabilitySearchResult searchResults = null;
            var businessIds = new List<long>();
            var currency = onlineAvailabilitySearchCriteria.RequestedCurrency;

            foreach (var shortName in onlineAvailabilitySearchCriteria.BusinessShortNames)
            {
                // will need to send the list of businesses in future
                CachedBusinessDigest currentBusiness = Cache.Cache.BusinessByShortName.TryGetValue(shortName);
                
                if (currentBusiness != null)
                {
                    businessIds.Add(currentBusiness.Id);
                    
                    if (currency == null || String.IsNullOrEmpty(currency))
                    {
                        currency = currentBusiness.WorkingCurrencyCode;
                    }
                }
            }

            if (businessIds.Any())
            {
                // Check that is not in the past
                onlineAvailabilitySearchCriteria.IsValid();

                if (onlineAvailabilitySearchCriteria.RoomSearchCriteria == null ||
                    onlineAvailabilitySearchCriteria.RoomSearchCriteria.Count == 0)
                {
                    onlineAvailabilitySearchCriteria.RoomSearchCriteria = new List<Model.Room.Online.RoomRestrictions>
                    {
                        new Model.Room.Online.RoomRestrictions {NumberOfAdults = null, NumberOfChildren = null}
                    };
                }

                Model.Room.Online.RoomRestrictions firstRestriction = onlineAvailabilitySearchCriteria.RoomSearchCriteria[0];

                Channel channel = channelDao.GetChannelByShortName(onlineAvailabilitySearchCriteria.ChannelShortName);

                if (channel == null)
                {
                    // Exception since this is online search source and channel id is required.
                    return GetNullBusinessAvailabilityResult(onlineAvailabilitySearchCriteria);
                }

                // Set up search criteria
                AvailabilitySearchCriteria searchCriteria = new AvailabilitySearchCriteria
                                                                {
                                                                    StartDate = onlineAvailabilitySearchCriteria.StartDate,
                                                                    EndDate = onlineAvailabilitySearchCriteria.EndDate,
                                                                    NumberOfAdults = firstRestriction.NumberOfAdults,
                                                                    NumberOfChildren = firstRestriction.NumberOfChildren,
                                                                    BusinessIds = businessIds,
                                                                    ChannelId = channel.Id,
                                                                    RequestedCurrency = currency
                                                                };
                
                // Do search here
                searchResults = CheckAvailability(searchCriteria);
            }
            else
            {
                // No businesses found so return null result for it
                searchResults = GetNullBusinessAvailabilityResult(onlineAvailabilitySearchCriteria);
            }

            var results = FilterSearchResultsForOnlineCheckAvailability(searchResults);
            Logger.LogInfo("==========CheckOnlineAvailability Returns==========");
            Logger.LogDebugAsXml(results);
            return results;
        }