Пример #1
0
        public ActionResult CategoryPostCount(CategoryPostCountModel model)
        {
            DateTime? fromDate = this.TryParseDateTime(model.DateFrom);
            DateTime? toDate = this.TryParseDateTime(model.DateTo);

            IList<CategoryPostCount> categories = this._repositoryService.GetTopCategoriesPostCount(fromDate: fromDate, toDate: toDate);
            this.PrepareCategoryPostCountModel(model, categories);

            return View(model);
        }
Пример #2
0
        public ActionResult CategoryPostCount()
        {
            DateTime fromDate = new DateTime(2013, 1, 1);
            DateTime toDate = new DateTime(2014, 1, 1);
            CategoryPostCountModel model = new CategoryPostCountModel()
            {
                DateFrom = fromDate.ToShortDateString(),
                DateTo = toDate.ToShortDateString()
            };

            IList<CategoryPostCount> categories = this._repositoryService.GetTopCategoriesPostCount(fromDate: fromDate, toDate: toDate);
            this.PrepareCategoryPostCountModel(model, categories);

            return View(model);
        }
Пример #3
0
        private void PrepareCategoryPostCountModel(CategoryPostCountModel model, IList<CategoryPostCount> categories)
        {
            model = model ?? new CategoryPostCountModel();

            if (!categories.IsEmpty())
            {
                StringBuilder sbPie = new StringBuilder(@"[");
                StringBuilder sbBarCount = new StringBuilder(@"[");
                StringBuilder sbBarCat = new StringBuilder(@"[");
                foreach (CategoryPostCount m in categories)
                {
                    m.Category = HttpUtility.JavaScriptStringEncode(string.Format("{0} ({1})", m.Category, m.PostCount));

                    sbPie.AppendFormat(@"['{0}', {1}],", m.Category, m.PostCount);

                    sbBarCount.AppendFormat(@"{0}, ", m.PostCount);
                    sbBarCat.AppendFormat(@"'{0}', ", m.Category);
                }
                sbPie.Append(@"]");
                sbBarCount.Append(@"]");
                sbBarCat.Append(@"]");

                model.JsonPie = sbPie.ToString();
                model.JsonBarCount = sbBarCount.ToString();
                model.JsonBarCategory = sbBarCat.ToString();
            }
        }