/// <summary>
        /// Get a credential for detailed display
        /// </summary>
        /// <param name="id"></param>
        /// <param name="user"></param>
        /// <param name="skippingCache">If true, do not use the cached version</param>
        /// <returns></returns>
        public static ThisEntity GetDetail(int id, bool skippingCache = false)
        {
            CredentialRequest cr = new CredentialRequest();

            cr.IsDetailRequest();

            return(GetDetail(id, cr, skippingCache));
        }
Ejemplo n.º 2
0
        public static WMA.CredentialDetail GetDetailForAPI(int id, bool skippingCache = false)
        {
            CredentialRequest cr = new CredentialRequest();

            cr.IsDetailRequest();
            cr.IncludingProcessProfiles = false;
            var entity = EntityHelper.GetDetail(id, cr, skippingCache);

            return(MapToAPI(entity));
        }
Ejemplo n.º 3
0
        public static void CredentialMinimumMap(EM.Credential from, Credential to)
        {
            CredentialRequest cr = new CredentialRequest();

            //probably too much
            cr.IsDetailRequest();

            to.Id    = from.Id;
            to.RowId = from.RowId;

            to.Name        = from.Name;
            to.Description = from.Description;

            to.SubjectWebpage = from.SubjectWebpage;
            to.CTID           = from.CTID;
            to.EntityStateId  = (int)from.EntityStateId;
            // 16-06-15 mp - always include credential type
            //can be null for a pending record
            to.CredentialTypeId = ( int )(from.CredentialTypeId ?? 0);
            if (to.CredentialTypeId > 0)
            {
                CodeItem ct = CodesManager.Codes_PropertyValue_Get(to.CredentialTypeId);
                if (ct != null && ct.Id > 0)
                {
                    to.CredentialType       = ct.Title;
                    to.CredentialTypeSchema = ct.SchemaName;
                }

                to.CredentialTypeEnum = EntityPropertyManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_CREDENTIAL_TYPE);
                to.CredentialTypeEnum.Items.Add(new EnumeratedItem()
                {
                    Id = to.CredentialTypeId, Name = ct.Name, SchemaName = ct.SchemaName
                });
            }

            if (from.ImageUrl != null && from.ImageUrl.Trim().Length > 0)
            {
                to.Image = from.ImageUrl;
            }
            else
            {
                to.Image = null;
            }

            if (IsValidDate(from.Created))
            {
                to.Created = ( DateTime )from.Created;
            }

            to.AudienceLevelType = EntityPropertyManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_AUDIENCE_LEVEL);

            //to.Occupation = Entity_FrameworkItemManager.FillEnumeration( to.RowId, CodesManager.PROPERTY_CATEGORY_SOC );
            to.Occupation       = Reference_FrameworksManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_SOC);
            to.OtherOccupations = Entity_ReferenceManager.GetAll(to.RowId, CodesManager.PROPERTY_CATEGORY_SOC);

            //to.Industry = Entity_FrameworkItemManager.FillEnumeration( to.RowId, CodesManager.PROPERTY_CATEGORY_NAICS );
            to.Industry        = Reference_FrameworksManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_NAICS);
            to.OtherIndustries = Entity_ReferenceManager.GetAll(to.RowId, CodesManager.PROPERTY_CATEGORY_NAICS);

            to.InstructionalProgramType = Reference_FrameworksManager.FillEnumeration(to.RowId, CodesManager.PROPERTY_CATEGORY_CIP);

            to.Subject = Entity_ReferenceManager.GetAllSubjects(to.RowId);

            to.Keyword = Entity_ReferenceManager.GetAll(to.RowId, CodesManager.PROPERTY_CATEGORY_KEYWORD);

            //Added these because they were needed on the detail page - NA 6/1/2017
            to.OwningAgentUid     = from.OwningAgentUid ?? Guid.Empty;
            to.OwningOrganization = OrganizationManager.GetForSummary(to.OwningAgentUid);
        }
        /// <summary>
        /// Get a minimal credential - typically for a link, or need just basic properties
        /// </summary>
        /// <param name="rowId"></param>
        /// <returns></returns>
        //public static ThisEntity GetBasicCredentialAsLink( Guid rowId )
        //{
        //    return CredentialManager.GetBasic( rowId, false, true );
        //}
        //public static ThisEntity GetBasicCredential( Guid rowId )
        //{
        //    return CredentialManager.GetBasic( rowId, false, false );
        //}

        /// <summary>
        /// Get a credential for detailed display
        /// </summary>
        /// <param name="id"></param>
        /// <param name="user"></param>
        /// <param name="skippingCache">If true, do not use the cached version</param>
        /// <returns></returns>
        public static ThisEntity GetDetail(int id, bool skippingCache = false)
        {
            //
            string   statusMessage = "";
            int      cacheMinutes  = UtilityManager.GetAppKeyValue("credentialCacheMinutes", 0);
            DateTime maxTime       = DateTime.Now.AddMinutes(cacheMinutes * -1);

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

            if (skippingCache == false &&
                HttpRuntime.Cache[key] != null && cacheMinutes > 0)
            {
                var cache = ( CachedCredential )HttpRuntime.Cache[key];
                try
                {
                    if (cache.LastUpdated > maxTime)
                    {
                        LoggingHelper.DoTrace(6, string.Format("===CredentialServices.GetCredentialDetail === Using cached version of Credential, Id: {0}, {1}", cache.Item.Id, cache.Item.Name));

                        return(cache.Item);
                    }
                }
                catch (Exception ex)
                {
                    LoggingHelper.DoTrace(6, "===CredentialServices.GetCredentialDetail === exception " + ex.Message);
                }
            }
            else
            {
                LoggingHelper.DoTrace(8, string.Format("****** CredentialServices.GetCredentialDetail === Retrieving full version of credential, Id: {0}", id));
            }

            DateTime start = DateTime.Now;

            CredentialRequest cr = new CredentialRequest();

            cr.IsDetailRequest();

            ThisEntity entity = CredentialManager.GetForDetail(id, cr);

            DateTime end     = DateTime.Now;
            var      elasped = end.Subtract(start).TotalSeconds;

            //Cache the output if more than specific seconds,
            //NOTE need to be able to force it for imports
            //&& elasped > 2
            if (key.Length > 0 && cacheMinutes > 0)
            {
                var newCache = new CachedCredential()
                {
                    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(5, string.Format("===CredentialServices.GetCredentialDetail $$$ Updating cached version of credential, Id: {0}, {1}", entity.Id, entity.Name));
                    }
                    else
                    {
                        LoggingHelper.DoTrace(5, string.Format("===CredentialServices.GetCredentialDetail ****** Inserting new cached version of credential, Id: {0}, {1}", entity.Id, entity.Name));

                        System.Web.HttpRuntime.Cache.Insert(key, newCache, null, DateTime.Now.AddMinutes(cacheMinutes), TimeSpan.Zero);
                    }
                }
            }
            else
            {
                LoggingHelper.DoTrace(7, string.Format("===CredentialServices.GetCredentialDetail $$$$$$ skipping caching of credential, Id: {0}, {1}, elasped:{2}", entity.Id, entity.Name, elasped));
            }

            return(entity);
        }