Exemple #1
0
        /// <summary>
        /// Retrieves the information about the selected event and assigns it to the CurrentEvent property of the User object
        /// Also retrieves any event-specific info about the User object (e.g CustomerGroupId)
        /// </summary>
        /// <param name="eventId">the Event Id</param>
        /// <param name="storeUserInformation">A item indicating whether must update the user information</param>
        public void SetCurrentEvent(int eventId, bool storeUserInformation)
        {
            // Sets the eventId into the GlobalUsers,
            // so that any successive calls will point to the correct database for the selected event
            IFrameworkSession frameworkSession = null;

            if (!HttpContext.Current.IsNull() &&
                !HttpContext.Current.Session.IsNull())
            {
                frameworkSession = HttpContext.Current.Session[WorkContextKeys.FrameworkSessionKey] as IFrameworkSession;
            }
            else
            {
                frameworkSession = IoC.Resolve <IFrameworkSession>();
            }

            if (frameworkSession.IsNull())
            {
                frameworkSession = IoC.Resolve <IFrameworkSession>();
            }

            frameworkSession.WebEventGlobalBaseUser.EventID = eventId;
            frameworkSession.WebEventGlobalUser.EventID     = eventId;

            if (storeUserInformation)
            {
                // Load the selected event's information
                // from the corresponding Check-In database
                // and save it to User's event

                // Saves the updated information to CurrentSession before requesting the latest changed event
                HttpContext.Current.Session[WorkContextKeys.FrameworkSessionKey] = frameworkSession;

                // Gets the latest changed event
                this.settingService.Event = IoC.Resolve <ICommonRepository>().GetCurrentEvent();

                SystemEvent selectedEvent = new SystemEvent(this.settingService.Event);
                this.workContext.CurrentUser.CurrentEvent = selectedEvent;

                // Load Event-specific information for the User (e.g. CustomerGroupId)
                // and amend it into the existing user
                User eventSpecificUserInfo = userService.GetUserById(this.workContext.CurrentUser.UserId);
                this.workContext.CurrentUser.OrgId           = eventSpecificUserInfo.OrgId;
                this.workContext.CurrentUser.OrgCode         = eventSpecificUserInfo.OrgCode;
                this.workContext.CurrentUser.CustomerGroupId = eventSpecificUserInfo.CustomerGroupId;

                IOrganisationService organisationService = IoC.Resolve <IOrganisationService>();
                if (eventSpecificUserInfo.OrgId > 0)
                {
                    this.workContext.CurrentUser.Organisation = organisationService.GetOrganisationById(eventSpecificUserInfo.OrgId);
                }

                if (eventSpecificUserInfo.CustomerGroupId != 0)
                {
                    this.workContext.CurrentUser.Organisations = new List <OrganisationBase>(organisationService.SelectOrganisationsByCustomerGroup(eventSpecificUserInfo.CustomerGroupId));
                    this.workContext.CurrentUser.CustomerGroup = organisationService.GetCustomerGroupByCustomerGroupId(eventSpecificUserInfo.CustomerGroupId);
                }

                this.workContext.CurrentUser.ChainId       = eventSpecificUserInfo.ChainId;
                this.workContext.CurrentUser.PreCheckInRef = eventSpecificUserInfo.PreCheckInRef;
                this.workContext.CurrentUser.HotelCode     = eventSpecificUserInfo.HotelCode;

                IHotelService hotelService = IoC.Resolve <IHotelService>();
                if (eventSpecificUserInfo.PreCheckInRef > 0 || !eventSpecificUserInfo.HotelCode.IsNullOrEmpty())
                {
                    this.workContext.CurrentUser.Hotel = hotelService.GetHotel(eventSpecificUserInfo.PreCheckInRef, eventSpecificUserInfo.HotelCode);
                }

                if (eventSpecificUserInfo.ChainId != 0)
                {
                    this.workContext.CurrentUser.Hotels = new List <Hotel>(hotelService.SelectHotels(eventSpecificUserInfo.ChainId));

                    var allHotelChains = new List <CheckInObjectLibrary.Setup.TableValue>(IoC.Resolve <IMainModuleService>().SelectHotelChains(eventId));
                    var userChain      = allHotelChains.Where(item => item.ValueId == eventSpecificUserInfo.ChainId)
                                         .FirstOrDefault();

                    if (!userChain.IsNull())
                    {
                        this.workContext.CurrentUser.Chain = userChain;
                    }
                }

                this.workContext.CurrentUser.Profiles = new List <UserProfile>(this.userService.SelectUserProfilesByUserId(this.workContext.CurrentUser.UserId));
            }

            // Save the updated information to CurrentSession
            HttpContext.Current.Session[WorkContextKeys.FrameworkSessionKey] = frameworkSession;
        }
Exemple #2
0
        /// <summary>
        /// Selects the Events for an user
        /// getting them by merging the framework events and web events
        /// </summary>
        /// <param name="userId">User identifier</param>
        /// <returns>Returns the contents of events</returns>
        public IEnumerable <SystemEvent> SelectEventsByUser(User user, int applicationId)
        {
            if (user.IsNull())
            {
                throw new ArgumentNullException("user");
            }

            IEnumerable <SystemEvent> effectiveEvents = new List <SystemEvent>();

            IFrameworkSession frameworkSession = IoC.Resolve <IFrameworkSession>();

            // If the user type is Framework then getting the framework events
            // using the same credentials
            if (user.Type == UserType.Framework)
            {
                effectiveEvents = this.frameworkAuthenticationRepository.SelectEventsByUser(user.LoginName, user.Password);

                var allowedSystemUserEvents = this.frameworkAuthenticationRepository.SelectEventsByUser(frameworkSession.WebEventGlobalBaseUser.Login, frameworkSession.WebEventGlobalBaseUser.Password);

                effectiveEvents = from allowedSystemUserEvent in allowedSystemUserEvents
                                  join effectiveEvent in effectiveEvents
                                  on allowedSystemUserEvent.EventId equals effectiveEvent.EventId
                                  select new SystemEvent()
                {
                    EventId   = effectiveEvent.EventId,
                    Code      = effectiveEvent.Code,
                    Name      = effectiveEvent.Name,
                    StartDate = effectiveEvent.StartDate,
                    EndDate   = effectiveEvent.EndDate,
                    Id        = effectiveEvent.Id
                };
            }
            // otherwise using the credentials from System Settings
            else
            {
                IEnumerable <SystemEvent> webEvents       = new List <SystemEvent>();
                IEnumerable <SystemEvent> frameworkEvents = this.frameworkAuthenticationRepository.SelectEventsByUser(frameworkSession.WebEventGlobalBaseUser.Login, frameworkSession.WebEventGlobalBaseUser.Password);

                // Get the event contents allowed from Master Web
                webEvents = this.systemEventRepository.SelectEventsByUser(user, applicationId);

                // Find the rest of the event information
                // from matching between web events and framework events
                effectiveEvents = from webEvent in webEvents
                                  join frameworkEvent in frameworkEvents
                                  on webEvent.EventId equals frameworkEvent.EventId
                                  select new SystemEvent()
                {
                    EventId   = frameworkEvent.EventId,
                    Code      = frameworkEvent.Code,
                    Name      = frameworkEvent.Name,
                    StartDate = frameworkEvent.StartDate,
                    EndDate   = frameworkEvent.EndDate,
                    Id        = frameworkEvent.Id
                };
            }

            // Multi-event application which use a cookie to determine the event
            string cookieEvent = CookieHelper.GetCookieString("event", true);

            if (effectiveEvents.Any() && !cookieEvent.IsNullOrEmpty())
            {
                effectiveEvents = from systemEvent in effectiveEvents
                                  where systemEvent.Code.Trim().Equals(cookieEvent, StringComparison.OrdinalIgnoreCase)
                                  select systemEvent;
            }

            effectiveEvents = from systemEvent in effectiveEvents
                              orderby systemEvent.EndDate descending
                              select systemEvent;

            return(effectiveEvents);
        }