/// <summary>
        /// Create a proxy guid for requested purpose
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="proxyType"></param>
        /// <param name="statusMessage"></param>
        /// <returns></returns>
        public string Create_ProxyLoginId(int userId, string proxyType, int expiryDays, ref string statusMessage)
        {
            EM.System_ProxyCodes efEntity = new EM.System_ProxyCodes();
            string proxyId = "";

            try
            {
                using (var context = new EntityContext())
                {
                    efEntity.UserId    = userId;
                    efEntity.ProxyCode = Guid.NewGuid().ToString();
                    //assuming if generated, not for identity
                    efEntity.IsIdentityProxy = false;
                    efEntity.Created         = System.DateTime.Now;
                    if (proxyType == SessionLoginProxy)
                    {
                        //expire at midnight - not really good for night owls
                        //efEntity.ExpiryDate = new System.DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 23, 59, 59 );
                        efEntity.ExpiryDate = System.DateTime.Now.AddDays(expiryDays);
                    }
                    else
                    {
                        efEntity.ExpiryDate = System.DateTime.Now.AddDays(expiryDays);
                    }

                    efEntity.IsActive  = true;
                    efEntity.ProxyType = proxyType;

                    context.System_ProxyCodes.Add(efEntity);

                    // submit the change to database
                    int count = context.SaveChanges();
                    if (count > 0)
                    {
                        statusMessage = "Successful";
                        int id = efEntity.Id;
                        return(efEntity.ProxyCode);
                    }
                    else
                    {
                        //?no info on error
                        return(proxyId);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Create_Proxy()");
                statusMessage = ex.Message;
                return(proxyId);
            }
        }
        public bool InactivateProxy(string proxyCode, ref string statusMessage)
        {
            bool isValid = true;

            using (var context = new EntityContext())
            {
                EM.System_ProxyCodes proxy = context.System_ProxyCodes.FirstOrDefault(s => s.ProxyCode == proxyCode);
                if (proxy != null && proxy.Id > 0)
                {
                    proxy.IsActive   = false;
                    proxy.AccessDate = System.DateTime.Now;

                    context.SaveChanges();
                }
            }

            return(isValid);
        }
        public bool Proxy_IsCodeActive(string proxyCode)
        {
            bool isValid = false;

            using (var context = new EntityContext())
            {
                EM.System_ProxyCodes proxy = context.System_ProxyCodes.FirstOrDefault(s => s.ProxyCode == proxyCode);
                if (proxy != null && proxy.Id > 0)
                {
                    if (proxy.IsActive &&
                        proxy.ExpiryDate > DateTime.Now)
                    {
                        isValid = true;
                    }
                }
            }

            return(isValid);
        }
        public bool Store_ProxyCode(string proxyCode, int userId, string proxyType, int expiryDays, ref string statusMessage)
        {
            bool isValid = true;

            EM.System_ProxyCodes efEntity = new EM.System_ProxyCodes();
            //string proxyId = "";
            try
            {
                using (var context = new EntityContext())
                {
                    efEntity.UserId    = userId;
                    efEntity.ProxyCode = proxyCode;
                    //assuming if storing existing, likely for identity
                    efEntity.IsIdentityProxy = true;
                    efEntity.Created         = System.DateTime.Now;
                    efEntity.ExpiryDate      = System.DateTime.Now.AddDays(expiryDays);

                    efEntity.IsActive  = true;
                    efEntity.ProxyType = proxyType;

                    context.System_ProxyCodes.Add(efEntity);

                    int count = context.SaveChanges();
                    if (count > 0)
                    {
                        statusMessage = "Successful";
                        int id = efEntity.Id;
                    }
                    else
                    {
                        //?no info on error
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingHelper.LogError(ex, thisClassName + ".Store_ProxyCode()");
                statusMessage = ex.Message;
                return(false);
            }
            return(isValid);
        }