Ejemplo n.º 1
0
        /// <summary>
        /// Returns the person matching this ID
        /// </summary>
        /// <param name="personID"></param>
        /// <returns></returns>
        public PersonList GetPerson(int?personID)
        {
            personID = personID.GetValueOrDefault(0);

            using (var cxt = DataStore.GetDataStore())
            {
                var data = (
                    from person in cxt.Person
                    where (person.PersonID == personID || personID == 0)
                    select person
                    ).ToList();

                data = data.ToList();
            }
            // Run through cache
            Func <string, PersonList> func = delegate(string cacheKey)
            {
                var result = new PersonList();
                using (var cxt = DataStore.GetDataStore())
                {
                    var data = (
                        from person in cxt.Person
                        where (person.PersonID == personID || personID == 0)
                        select person
                        ).ToList();
                    result.AddRange(data);
                }
                result.CacheKey = cacheKey;
                if (personID > 0)
                {
                    result.AddTag(CacheTags.Person, personID);
                }
                return(result);
            };

            var cache = Dependency.Resolve <ICacheManager>();
            var key   = new PersonList()
            {
                CacheKey = "person_" + personID.ToString()
            };
            var list = cache.Load(key, func);

            return(list);
        }