コード例 #1
0
        /// <summary>
        /// Zbudowanie modelu
        /// </summary>
        /// <param name="statementType">Typ zestawienia</param>
        /// <param name="Page">Numer żądanej strony</param>
        /// <param name="SortExpression">Pole do sortowania</param>
        /// <param name="Ascending">Czy sortować rosnąco</param>
        /// <param name="filter">Obiekt filtrów</param>
        private StatisticsStatementListViewModel CreateModel(StatisticsStatementType statementType,
                                                             int?Page,
                                                             string SortExpression,
                                                             bool?Ascending,
                                                             StatisticsStatementListViewModelFilter filter)
        {
            var       page           = Page ?? 1;
            var       sortExpression = string.IsNullOrEmpty(SortExpression) ? "TotalDisplayCount" : SortExpression;
            var       ascending      = Ascending.HasValue && Ascending.Value;
            const int itemsPerPage   = 10;

            // Zbuduj obiekt informacyjny dla stronnicowania
            var paginationInfo = new AdPaginationInfo
            {
                Accending      = ascending,
                ItemsPerPage   = itemsPerPage,
                RequestedPage  = page,
                SortExpression = sortExpression
            };

            var statements = _repository.StatisticsStatements(filter, paginationInfo, statementType, (User.IsInRole("Admin") ? 0 : User.GetUserIDInt()));

            var model = new StatisticsStatementListViewModel
            {
                StatementType   = statementType,
                Statement       = statements.ToList(),
                CurrentPage     = paginationInfo.RequestedPage,
                SortExpression  = paginationInfo.SortExpression,
                NumberOfResults = paginationInfo.OutResultsFound,
                ItemsPerPage    = paginationInfo.ItemsPerPage,
                SortAccending   = paginationInfo.Accending,
                Filters         = filter ?? new StatisticsStatementListViewModelFilter()
            };

            // Określ adres powrotny w zależności od wybranego rodzaju zestawienia
            switch (statementType)
            {
            case StatisticsStatementType.Campaign:
                model.DestinationURL = "Campaign";
                model.StatementTitle = "Zestawienie kampanii";
                break;

            case StatisticsStatementType.MultimediaObject:
                model.DestinationURL = "MultimediaObjects";
                model.StatementTitle = "Zestawienie obiektów multimedialnych";
                break;

            default:
                model.StatementTitle = "Zestawienie";
                break;
            }

            return(model);
        }
コード例 #2
0
        /// <summary>
        /// Wybiera odpowiedną akcję
        /// </summary>
        /// <param name="statementType"></param>
        private string ChooseAction(StatisticsStatementType statementType)
        {
            switch (statementType)
            {
            // Zestawienia kampanii
            case StatisticsStatementType.Campaign:
                return("CampaignStatement");

            // Zestawienia obiektów multimedialnych
            case StatisticsStatementType.MultimediaObject:
                return("MultimediaObjectStatement");

            default:
                return("Index");
            }
        }
コード例 #3
0
        /// <summary>
        /// Kolekcja dostępnych zestawień statystyk
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="paginationInfo"></param>
        /// <param name="statementType"></param>
        /// <param name="userId">Id użytkownika</param>
        public IQueryable <StatisticsStatementItem> StatisticsStatements(StatisticsStatementListViewModelFilter filter,
                                                                         Entities.AdPaginationInfo paginationInfo, StatisticsStatementType statementType, int userId)
        {
            //TODO: Poprawić to!
            List <IGrouping <int, StatementQueryRow> > objectsGroup = null;

            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            switch (statementType)
            {
            case StatisticsStatementType.Campaign:
                objectsGroup = GetCampaignQuery(filter, userId);
                break;

            case StatisticsStatementType.MultimediaObject:
                objectsGroup = GetMultimediaObjectsQuery(filter, userId);
                break;
            }
            sw.Stop();
            TimeSpan getXQueryTime = sw.Elapsed;

            sw.Reset();
            var skip = 0;

            if (paginationInfo != null)
            {
                paginationInfo.OutResultsFound = objectsGroup.Count();
                skip = GetSkip(paginationInfo.RequestedPage, paginationInfo.ItemsPerPage, paginationInfo.OutResultsFound);
            }

            const int www     = (int)ADServerDAL.Models.Statistic.RequestSourceType.WWW;
            const int desktop = (int)ADServerDAL.Models.Statistic.RequestSourceType.Desktop;

            var statements = new List <StatisticsStatementItem>();

            sw.Start();
            var statisticsToCategories = (from c in Context.Categories
                                          select new StatisticToParentItem
            {
                ParentName = c.Name,
                StatisticId = 1
            }).ToList();

            sw.Stop();
            TimeSpan statisticsToCategoriesTime = sw.Elapsed;

            sw.Reset();

            sw.Start();

            if (objectsGroup != null && objectsGroup.Count > 0)
            {
                statements.AddRange(
                    objectsGroup.Select(@group => new StatisticsStatementItem
                {
                    Id   = @group.Key,
                    Name = @group.Select(x => x.ObjectName).FirstOrDefault(),
                    Type = statementType,
                    TotalDisplayCount   = @group.Count(x => x.StatisticId > 0),
                    WWWDisplayCount     = @group.Count(x => x.Source == www),
                    DesktopDisplayCount = @group.Count(x => x.Source == desktop),
                    Categories          = GetCategories(@group.ToList(), statisticsToCategories),
                    ClickedCount        = @group.Count(x => x.Clicked),
                    AdPointsCount       = @group.Sum(x => x.AdPoints),
                    cAdPoints           = statementType == StatisticsStatementType.Campaign ? @group.Select(x => x.cAdPoints).FirstOrDefault() : default(decimal?)
                }));
            }
            sw.Stop();

            TimeSpan foreachTime = sw.Elapsed;

            return
                (statements.AsQueryable()
                 .OrderByDescending(x => x.TotalDisplayCount)
                 .ThenBy(x => x.Name)
                 .Skip(skip)
                 .Take(paginationInfo == null ? 10 : paginationInfo.ItemsPerPage));
        }