public int GetSpotFileTypeID(SpotFileTypes oSpotFileType) { var iSpotFileTypeID = 0; var sCacheItemKey = "SpotFileType-" + oSpotFileType.ToString(); if (HttpContext.Current.Cache[sCacheItemKey] == null) { iSpotFileTypeID = GetSpotFileTypeFromDB(oSpotFileType).IASpotFileTypeID; HttpContext.Current.Cache.Add(sCacheItemKey, iSpotFileTypeID, null, DateTime.Now.AddSeconds(3600), TimeSpan.Zero, CacheItemPriority.Normal, null); } else { iSpotFileTypeID = (int) HttpContext.Current.Cache[sCacheItemKey]; } return iSpotFileTypeID; }
/// <summary> /// Retreives the apporpirate SpotFileType object from the DB based on the enum value passed in /// </summary> /// <param name="oSpotFileType"></param> /// <returns></returns> private IASpotFileType GetSpotFileTypeFromDB(SpotFileTypes oSpotFileType) { IASpotFileType oIASpotFileType = null; switch (oSpotFileType) { case SpotFileTypes.Production: oIASpotFileType = DataAccess.IASpotFileTypes.SingleOrDefault(row => row.Name == "Production"); break; case SpotFileTypes.Talent: oIASpotFileType = DataAccess.IASpotFileTypes.SingleOrDefault(row => row.Name == "Talent"); break; default: throw new ApplicationException(string.Format("Spot file type is undefined or doesn't exist: {0}", oSpotFileType.ToString())); } return oIASpotFileType; }