예제 #1
0
 public House GetHouse(Guid id)
 {
     using (new ElevatedModeRegion(this.manager))
     {
         var house = HouseCache.Get(id.ToString());
         if (house == null)
         {
             var houses = this.LoadHouses().ToList();
             house = houses.FirstOrDefault(h => h.Id == id);
             if (house != null)
             {
                 var activities = this.manager.GetChildItems(new List <Guid>()
                 {
                     house.Id
                 }, HogwartsConstants.activityType).Where(a => a.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live).ToList();
                 house.Points = activities != null && activities.Count > 0 ? Convert.ToInt32(activities.Select(a => a.GetValue <decimal>("Points")).Sum()) : 0;
                 HouseCache.Add(house.Id.ToString(), house);
             }
             else
             {
                 house = null;
             }
         }
         return(house);
     }
 }
예제 #2
0
        public IEnumerable <House> GetHouses()
        {
            using (new ElevatedModeRegion(this.manager))
            {
                var keys = HouseCache.GetKeys();

                // if cache is empty, initialize the cache
                if (keys == null)
                {
                    var houses = LoadHouses();
                    keys = houses.Select(m => m.Id.ToString()).ToList();
                    HouseCache.AddKeys(keys);
                }

                List <House> houseModels = new List <House>();
                foreach (var key in keys)
                {
                    houseModels.Add(GetHouse(Guid.Parse(key)));
                }

                return(houseModels);
            }
        }