Пример #1
0
 public SessionValue getSessionValue(int sessionID, string probertyName)
 {
     using (Entities.Entities ctx = new Entities.Entities())
     {
         SessionValue sessionValue = ctx.SessionValues.Where(x => x.SessionID == sessionID && x.PrortyName == probertyName).FirstOrDefault();
         return(sessionValue);
     }
 }
Пример #2
0
        /// <summary>
        /// Removes an item from the session
        /// </summary>
        /// <param name="sessionKey">Name of the session object</param>
        public static void RemoveSessionValue(SessionValue sessionKey)
        {
            HttpSessionState session = HttpContext.Current.Session;

            if (SessionKeyExists(sessionKey.ToString()))
            {
                session.Remove(sessionKey.ToString());
            }
        }
Пример #3
0
        public bool alterSerssionProbertyValue(SessionValue sessionValue, string probertyValue)
        {
            int check = 0;

            using (Entities.Entities ctx = new Entities.Entities())
            {
                sessionValue.SessionValue1    = probertyValue;
                ctx.Entry(sessionValue).State = System.Data.Entity.EntityState.Modified;
                check = ctx.SaveChanges();
            }
            return(check > 0 ? true : false);
        }
Пример #4
0
        public bool AddSessionProbertyValue(int sessionID, string probertyName, string probertyValue)
        {
            int check = 0;

            using (Entities.Entities ctx = new Entities.Entities())
            {
                SessionValue sv = new SessionValue {
                    SessionID = sessionID, PrortyName = probertyName, SessionValue1 = probertyValue
                };
                ctx.SessionValues.Add(sv);
                check = ctx.SaveChanges();
            }
            return(check > 0 ? true : false);
        }
Пример #5
0
        private SessionValue FetchOrCreateSessionValue(string key, string value)
        {
            var sv = FetchSessionValue(key, out bool cached);

            if (sv == null && value != null && CurrentSessionId != null)
            {
                sv = new SessionValue
                {
                    Name        = key,
                    SessionId   = CurrentSessionId,
                    CreatedDate = DateTime.UtcNow
                };
                db.SessionValues.InsertOnSubmit(sv);
            }
            if (sv != null)
            {
                if (value == null)
                {
                    db.SessionValues.DeleteAllOnSubmit(db.SessionValues.Where(v => v.Name == key && v.SessionId == CurrentSessionId));
                    LocalCache.Remove(key);
                }
                else
                {
                    LocalCache[key] = value;
                    if (cached && value != sv.Value)
                    {
                        sv = db.SessionValues.FirstOrDefault(v => v.Name == key && v.SessionId == CurrentSessionId);
                    }
                    sv.Value = value;
                }
                try
                {
                    db.SubmitChanges();
                }
                catch (Exception)
                {
                    if (Util.IsDebug())
                    {
                        throw;
                    }
                }
            }
            return(sv);
        }
Пример #6
0
        public bool setSessionProbertyValue(string sessionName, string userID, string probertyName, string probertyValue)
        {
            SessionState sessionStateDAL = new SessionState();
            bool         check           = false;

            int sessionID = sessionStateDAL.getSessionID(sessionName, userID);

            SessionValue sessionValue = sessionStateDAL.getSessionValue(sessionID, probertyName);

            if (sessionValue == null)
            {
                check = sessionStateDAL.AddSessionProbertyValue(sessionID, probertyName, probertyValue);
            }
            else
            {
                check = sessionStateDAL.alterSerssionProbertyValue(sessionValue, probertyValue);
            }

            return(check);
        }
Пример #7
0
        /// <summary>
        /// Retrieves an item from the session cache
        /// </summary>
        /// <param name="sessionKey">Name of the session object</param>
        /// <returns>Object - the item being retrieved from the session store</returns>
        public static object GetSessionValue(SessionValue sessionKey)
        {
            object retVal;
            HttpSessionState session = ((HttpSessionState)HttpContext.Current.Session);

            try
            {
                if (SessionKeyExists(sessionKey.ToString()))
                {
                    retVal = session[sessionKey.ToString()];
                }
                else
                {
                    retVal = null;
                }
            }
            catch (Exception)
            {
                retVal = null;
            }

            return retVal;
        }
Пример #8
0
 /// <summary>
 /// Saves a session object for a Key
 /// </summary>
 /// <param name="sessionKey">Name of the session object</param>
 /// <param name="objectValue">The object value.</param>
 public static void SaveSessionValue(SessionValue sessionKey, object objectValue)
 {
     HttpContext.Current.Session[sessionKey.ToString()] = objectValue;
 }
Пример #9
0
        /// <summary>
        /// Saves a value to the session cache
        /// </summary>
        /// <param name="sessionKey">Name of the session object</param>
        /// <param name="sessionObject">Item being saved in the session</param>
        public static void SetSessionValue(SessionValue sessionKey, Object sessionObject)
        {
            HttpSessionState session = HttpContext.Current.Session;

            try
            {
                if (SessionKeyExists(sessionKey.ToString()))
                {
                    session.Remove(sessionKey.ToString());
                }

                session.Add(sessionKey.ToString(), sessionObject);
            }
            catch (Exception)
            {
                // do nothing
            }
        }
Пример #10
0
        /// <summary>
        /// Checks whether a key exists in the current session
        /// </summary>
        /// <param name="sessionKey">SessionValue enum</param>
        /// <returns>Boolean - -True for the existence of the session key</returns>
        public static bool SessionKeyExists(SessionValue sessionKey)
        {
            bool keyExists = false;
            HttpSessionState session = HttpContext.Current.Session;

            foreach (string key in session.Keys)
            {
                if (key.Equals(sessionKey.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    keyExists = true;
                    break;
                }
            }

            return keyExists;
        }