HasLocations() public method

Gets a value indicating whether this instance has active locations.
public HasLocations ( List configuredGroupTypes ) : bool
configuredGroupTypes List
return bool
Beispiel #1
0
        /// <summary>
        /// Determines whether [is temporarily closed] [the specified kiosk].
        /// </summary>
        /// <param name="kiosk">The kiosk.</param>
        /// <param name="configuredGroupTypeIds">The configured group type ids.</param>
        /// <param name="checkInState">State of the check in.</param>
        /// <returns>
        ///   <c>true</c> if [is temporarily closed] [the specified kiosk]; otherwise, <c>false</c>.
        /// </returns>
        private static bool IsTemporarilyClosed(KioskDevice kiosk, List <int> configuredGroupTypeIds, CheckInState checkInState)
        {
            bool isTemporarilyClosed = (!kiosk.HasLocations(configuredGroupTypeIds) && !checkInState.AllowCheckout) ||
                                       (checkInState.AllowCheckout && !kiosk.HasActiveCheckOutLocations(configuredGroupTypeIds));

            return(isTemporarilyClosed);
        }
Beispiel #2
0
        /// <summary>
        /// Reads the device by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="configuredGroupTypes">The configured group types.</param>
        /// <returns></returns>
        public static KioskDevice Read(int id, List <int> configuredGroupTypes)
        {
            string cacheKey = KioskDevice.CacheKey(id);

            ObjectCache cache  = MemoryCache.Default;
            KioskDevice device = cache[cacheKey] as KioskDevice;

            // If the kioskdevice is currently inactive, but has a next active time prior to now, force a refresh
            if (device != null && device.FilteredGroupTypes(configuredGroupTypes).Count > 0 && !device.HasLocations(configuredGroupTypes))
            {
                if (device.KioskGroupTypes.Select(g => g.NextActiveTime).Min().CompareTo(DateTimeOffset.Now) < 0)
                {
                    device = null;
                }
            }

            if (device != null)
            {
                return(device);
            }
            else
            {
                var deviceModel = new DeviceService().Get(id);

                if (deviceModel != null)
                {
                    device = new KioskDevice(deviceModel);

                    using (new Rock.Data.UnitOfWorkScope())
                    {
                        foreach (Location location in deviceModel.Locations)
                        {
                            LoadKioskLocations(device, location);
                        }
                    }

                    var cachePolicy = new CacheItemPolicy();
                    cachePolicy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(60);
                    cache.Set(cacheKey, device, cachePolicy);

                    return(device);
                }
            }

            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// Reads the device by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="configuredGroupTypes">The configured group types.</param>
        /// <returns></returns>
        public static KioskDevice Read(int id, List <int> configuredGroupTypes)
        {
            string cacheKey = KioskDevice.CacheKey(id);

            ObjectCache cache  = Rock.Web.Cache.RockMemoryCache.Default;
            KioskDevice device = cache[cacheKey] as KioskDevice;

            // If the kioskdevice is currently inactive, but has a next active time prior to now, force a refresh
            if (device != null && device.FilteredGroupTypes(configuredGroupTypes).Count > 0 && !device.HasLocations(configuredGroupTypes))
            {
                if (device.KioskGroupTypes.Select(g => g.NextActiveTime).Min().CompareTo(RockDateTime.Now) < 0)
                {
                    device = null;
                }
            }

            if (device != null)
            {
                return(device);
            }
            else
            {
                using (var rockContext = new RockContext())
                {
                    var campusLocations = new Dictionary <int, int>();
                    Rock.Web.Cache.CampusCache.All()
                    .Where(c => c.LocationId.HasValue)
                    .Select(c => new
                    {
                        CampusId   = c.Id,
                        LocationId = c.LocationId.Value
                    })
                    .ToList()
                    .ForEach(c => campusLocations.Add(c.CampusId, c.LocationId));

                    var deviceModel = new DeviceService(rockContext)
                                      .Queryable("Locations")
                                      .Where(d => d.Id == id)
                                      .FirstOrDefault();

                    if (deviceModel != null)
                    {
                        device = new KioskDevice(deviceModel);
                        foreach (Location location in deviceModel.Locations)
                        {
                            LoadKioskLocations(device, location, campusLocations, rockContext);
                        }

                        var cachePolicy = new CacheItemPolicy();
                        cachePolicy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(60);
                        cache.Set(cacheKey, device, cachePolicy);

                        return(device);
                    }
                }
            }

            return(null);
        }