Esempio n. 1
0
        /// <summary>
        /// Methoda zwraca filtr
        /// </summary>
        /// <typeparam name="T">Typ filtru</typeparam>
        /// <param name="filterKey">Klucz do zapisanego filtra w sesji</param>
        /// <param name="settingsKey">Klucz do zapisanych stawień w sesji</param>
        /// <param name="page">Strona</param>
        /// <param name="sortExpression">Wyrażenie sortowania</param>
        /// <param name="accending">rosnące?</param>
        /// <returns></returns>
        private T PageSettingsOrder <T>(FilterSettingsKey filterKey, PageSettingsKey settingsKey, ref int?page, ref string sortExpression, ref bool?accending)
        {
            var filter = default(T);

            // Pobranie aktualnych filtrów z sesji
            if (Session != null)
            {
                filter = (T)Session[filterKey.ToString()];
            }

            if (filter == null)
            {
                filter = Activator.CreateInstance <T>();
            }

            if (Session != null)
            {
                Session[filterKey.ToString()] = filter;

                PageSettings.RemoveFromSessionExcept(settingsKey);
                FilterSettings.RemoveFromSessionExcept(filterKey);

                var pageSettings = PageSettings.GetFromSession(settingsKey);
                if (pageSettings != null)
                {
                    if (!page.HasValue)
                    {
                        page = pageSettings.Page;
                    }
                    if (!accending.HasValue)
                    {
                        accending = pageSettings.Accending;
                    }
                    if (string.IsNullOrEmpty(sortExpression))
                    {
                        sortExpression = pageSettings.SortExpression;
                    }
                }
                else
                {
                    pageSettings = new PageSettings();
                }

                pageSettings.Page           = page ?? 1;
                pageSettings.Accending      = !accending.HasValue || accending.Value;
                pageSettings.SortExpression = string.IsNullOrEmpty(sortExpression) ? "Id" : sortExpression;

                Session[settingsKey.ToString()] = pageSettings;
            }
            return(filter);
        }
Esempio n. 2
0
 /// <summary>
 /// Usuwana obiekty filtrów z sesji za wyjątkiem zadanego klucza
 /// </summary>
 /// <param name="exception">Wyjątek - klucz, który nie zostanie usunięty z sesji</param>
 public static void RemoveFromSessionExcept(FilterSettingsKey exception)
 {
     if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Session != null)
     {
         string[] namesToRemove = Enum.GetNames(typeof(FilterSettingsKey)).Except(new string[] { exception.ToString() }).ToArray();
         foreach (string name in namesToRemove)
         {
             if (System.Web.HttpContext.Current.Session[name] != null)
             {
                 System.Web.HttpContext.Current.Session[name] = null;
                 System.Web.HttpContext.Current.Session.Remove(name);
             }
         }
     }
 }