Пример #1
0
        public static void AddLearningOpportunityToCache(LearningOpportunityProfile entity)
        {
            int cacheMinutes = UtilityManager.GetAppKeyValue("learningOppCacheMinutes", 0);

            string key = "LearningOpportunity_" + entity.Id.ToString();

            if (cacheMinutes > 0)
            {
                var newCache = new CachedLearningOpportunity()
                {
                    Item        = entity,
                    lastUpdated = DateTime.Now
                };
                if (HttpContext.Current != null)
                {
                    if (HttpContext.Current.Cache[key] != null)
                    {
                        HttpRuntime.Cache.Remove(key);
                        HttpRuntime.Cache.Insert(key, newCache);

                        LoggingHelper.DoTrace(7, string.Format("%%%CacheManager.AddLearningOpportunityToCache $$$ Updating cached version of LearningOpportunity, Id: {0}, {1}", entity.Id, entity.Name));
                    }
                    else
                    {
                        LoggingHelper.DoTrace(7, string.Format("%%%CacheManager.AddLearningOpportunityToCache ****** Inserting new cached version of LearningOpportunity, Id: {0}, {1}", entity.Id, entity.Name));

                        System.Web.HttpRuntime.Cache.Insert(key, newCache, null, DateTime.Now.AddHours(cacheMinutes), TimeSpan.Zero);
                    }
                }
            }

            //return entity;
        }
Пример #2
0
        //

        public ActionResult LearningOpportunity(string id, string name = "")
        {
            //LearningOpportunityProfile entity = new LearningOpportunityProfile();
            int           loppId        = 0;
            var           entity        = new LearningOpportunityProfile();
            string        refresh       = Request.Params["refresh"];
            bool          skippingCache = FormHelper.GetRequestKeyValue("skipCache", false);
            List <string> messages      = new List <string>();

            if (int.TryParse(id, out loppId))
            {
                entity = LearningOpportunityServices.GetDetail(loppId, skippingCache);
            }
            else if (ServiceHelper.IsValidCtid(id, ref messages))
            {
                entity = LearningOpportunityServices.GetDetailByCtid(id, skippingCache);
            }
            else
            {
                SetPopupErrorMessage("ERROR - Enter the ctid which starts with 'ce' or Enter the id ");
                return(RedirectToAction("Index", "Home"));
            }
            //HttpContext.Server.ScriptTimeout = 300;

            if (entity.Id == 0)
            {
                SetPopupErrorMessage("ERROR - the requested LearningOpportunity record was not found ");
                return(RedirectToAction("Index", "Home"));
            }
            ActivityServices.SiteActivityAdd("LearningOpportunity", "View", "Detail", string.Format("User viewed LearningOpportunity: {0} ({1})", entity.Name, entity.Id), 0, 0, loppId);

            return(View("~/Views/Detail/Detail.cshtml", entity));
        }
Пример #3
0
        public static bool IsLearningOpportunityAvailableFromCache(int id, ref LearningOpportunityProfile entity)
        {
            int      cacheMinutes = UtilityManager.GetAppKeyValue("learningOppCacheMinutes", 0);
            DateTime maxTime      = DateTime.Now.AddMinutes(cacheMinutes * -1);

            string key = "LearningOpportunity_" + id.ToString();

            if (HttpRuntime.Cache[key] != null && cacheMinutes > 0)
            {
                var cache = ( CachedLearningOpportunity )HttpRuntime.Cache[key];
                try
                {
                    if (cache.lastUpdated > maxTime)
                    {
                        LoggingHelper.DoTrace(7, string.Format("%%%CacheManager.IsLearningOpportunityAvailableFromCache === Using cached version of LearningOpportunity, Id: {0}, {1}", cache.Item.Id, cache.Item.Name));

                        //check if user can update the object
                        //string status = "";
                        //if ( !CanUserUpdateCredential( id, user, ref status ) )
                        //	cache.Item.CanEditRecord = false;

                        entity = cache.Item;
                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    LoggingHelper.DoTrace(6, "%%%CacheManager.IsLearningOpportunityAvailableFromCache === exception " + ex.Message);
                }
            }

            return(false);
        }