Exemplo n.º 1
0
        public ActionResult List(StatisticsListViewModelFilter model)
        {
            if (Session != null)
            {
                Session[FilterSettingsKey.StatisticsControllerFilterList.ToString()] = model;
                PageSettings.RemoveFromSession(PageSettingsKey.StatisticsPageSettings);
            }

            return(Json(true));
        }
        /// <summary>
        /// Customowe filtrowanie
        /// </summary>
        /// <typeparam name="T">Typ filtru</typeparam>
        /// <param name="_query">Zbiór encji</param>
        /// <param name="_filter">filtr</param>
        /// <returns></returns>
        protected T FilterSettingsDetailsVirtual <T, Q>(ref IQueryable <Q> _query, T _filter)
        {
            var     query   = (IQueryable <Statistic>)_query;
            dynamic filter1 = _filter;
            StatisticsListViewModelFilter filter = filter1;
            var doFiltering = filter != null && filter.Filtering;

            if (doFiltering)
            {
                if (filter.FilterDateFrom.HasValue)
                {
                    var dtS = filter.FilterDateFrom.Value.Date;
                    query = query.Where(q => dtS <= q.RequestDate || dtS <= q.ResponseDate);
                }

                if (filter.FilterDateTo.HasValue)
                {
                    var dtE = filter.FilterDateTo.Value.Date.AddDays(1).AddSeconds(-1);
                    query = query.Where(q => dtE >= q.RequestDate || dtE >= q.ResponseDate);
                }

                if (!string.IsNullOrEmpty(filter.FilterMultimediaObjectName))
                {
                    query = query.Where(q => q.MultimediaObject.Name.ToLower().Contains(filter.FilterMultimediaObjectName.ToLower()));
                }

                if (filter.FilterMultimediaObjectId.HasValue)
                {
                    query = query.Where(q => q.MultimediaObjectId == filter.FilterMultimediaObjectId.Value);
                }

                if (!string.IsNullOrEmpty(filter.FilterRequestIP))
                {
                    query = query.Where(q => q.RequestIP.ToLower().Contains(filter.FilterRequestIP.ToLower()));
                }
                if (!string.IsNullOrEmpty(filter.FilterCampaignName))
                {
                    query = query.Where(q => q.Campaign.Name.ToLower().Contains(filter.FilterCampaignName.ToLower()));
                }
            }

            _query  = (IQueryable <Q>)query;
            filter1 = filter;

            return((T)filter1);
        }
        public ActionResult MultimediaObjectStatement(int?page,
                                                      string sortExpression,
                                                      bool?ascending)
        {
            // Odtwórz zapamiętane filtry
            StatisticsStatementListViewModelFilter filter = null;

            if (Session != null)
            {
                filter = Session[FilterSettingsKey.StatisticsStatementControllerFilterList.ToString()] as StatisticsStatementListViewModelFilter;
            }

            if (filter == null)
            {
                filter = new StatisticsStatementListViewModelFilter();
                var filtr2 = new StatisticsListViewModelFilter
                {
                    FilterDateFrom = filter.FilterDateFrom,
                    FilterDateTo   = filter.FilterDateTo
                };
                Session[FilterSettingsKey.ObjDetailsFilterList.ToString()] = filtr2;
            }

            // Zapamiętaj aktualne filtry
            if (Session != null)
            {
                Session[FilterSettingsKey.StatisticsStatementControllerFilterList.ToString()] = filter;

                PageSettings.RemoveFromSessionExcept(PageSettingsKey.StatisticsStatementObjectsPageSettings);
                //FilterSettings.RemoveFromSessionExcept(FilterSettingsKey.StatisticsStatementControllerFilterList);

                PageSettings pageSettings = PageSettings.GetFromSession(PageSettingsKey.StatisticsStatementObjectsPageSettings);
                if (pageSettings != null)
                {
                    if (!page.HasValue)
                    {
                        page = pageSettings.Page;
                    }
                    if (!ascending.HasValue)
                    {
                        ascending = pageSettings.Accending;
                    }
                    if (string.IsNullOrEmpty(sortExpression))
                    {
                        sortExpression = pageSettings.SortExpression;
                    }
                }
                else
                {
                    pageSettings = new PageSettings();
                }

                pageSettings.Page      = page ?? 1;
                pageSettings.Accending = !ascending.HasValue || ascending.Value;

                Session[PageSettingsKey.StatisticsStatementObjectsPageSettings.ToString()] = pageSettings;
            }

            // Zbuduj i zwróć model
            StatisticsStatementListViewModel model = CreateModel(StatisticsStatementType.MultimediaObject, page, sortExpression, ascending, filter);

            var id = User.GetUserIDInt();
            var u  = _usersRepository.Users.Single(it => it.Id == id);

            ViewBag.AdPoints = u.AdPoints;

            return(View("Index", model));
        }