public ActionResult ManagementTab(int?week, int?year, string tab = "needreview")
        {
            if (User.IsInRole("Writter"))
            {
                tab = "neededit";
            }
            ViewBag.tab = tab;

            MyArticlesView view = new MyArticlesView();

            view.NeedEditList   = _articleRepository.All.Where(a => a.ArticleStatus == (int)ArticleStatus.NeedEdit).ToList();
            view.NeedReviewList = _articleRepository.All.Where(a => a.ArticleStatus == (int)ArticleStatus.NeedReview).ToList();
            view.GoodList       = _articleRepository.All.Where(a => a.ArticleStatus == (int)ArticleStatus.Good && !a.IsPublished).ToList();
            view.RejectList     = _articleRepository.All.Where(a => a.ArticleStatus == (int)ArticleStatus.Reject).ToList();
            //view.PublishedList = _articleRepository.All.Where(a => a.IsPublished).ToList();

            var      now = DateTime.Now;
            var      articlesQuery = _articleRepository.GetMany(art => art.ArticleStatus > 0, art => art.PublishedTime);
            DateTime begin, end;

            if (!year.HasValue)
            {
                year = now.Year;
            }
            if (week.HasValue)
            {
                end = Utilities.GetLastDateOfWeek(year.Value, week.Value, DayOfWeek.Sunday);
            }
            else
            {
                end = Utilities.GetLastDateOfWeek(now, DayOfWeek.Sunday);
            }
            begin = end.AddDays(-7 * 5).AddDays(1);

            articlesQuery = articlesQuery.Where(v => v.PublishedTime.HasValue && v.PublishedTime.Value.Date >= begin && v.PublishedTime.Value.Date <= end);


            var      startDate = begin;
            DateTime endDate;
            var      publishedList = new List <ArticleCustomDateView>();

            for (int i = 0; i < 5; i++)
            {
                endDate = startDate.AddDays(6);
                var weekList = new ArticleCustomDateView
                {
                    Week      = cal.GetWeekOfYear(startDate, System.Globalization.CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday),
                    StartDate = startDate,
                    EndDate   = endDate,
                    Articles  = articlesQuery.Where(art => art.IsPublished && art.PublishedTime.HasValue && art.PublishedTime.Value.Date >= startDate && art.PublishedTime.Value.Date <= endDate)
                                .GroupJoin(_articleSeriesRepository.All, art => art.ArticleSeriesId, asr => asr.Id, (art, asr) => new { Art = art, Srs = asr })
                                .SelectMany(xy => xy.Srs.DefaultIfEmpty(), (x, y) => new { Art = x.Art, Srs = y })
                                .Select(a => new ArticleCustomView()
                    {
                        Id            = a.Art.Id,
                        ArticleName   = a.Art.Title,
                        SeriesName    = a.Srs != null && a.Srs.Articles.Count > 0 ? a.Srs.Name : "",
                        SeriesId      = a.Srs != null ? a.Srs.Id : 0,
                        IsPublished   = a.Art.IsPublished,
                        Order         = a.Art.Order,
                        PublishedTime = a.Art.PublishedTime,
                        Thumbnail     = a.Art.Thumbnail,
                        CatThumbnail  = a.Art.Categories.Count > 0 ? a.Art.Categories.ElementAt(0).ProfilePhoto : "",
                        CatName       = String.Join(", ", a.Art.Categories.OrderBy(r => r.Order).Select(r => r.Name)),
                        Reporters     = a.Art.Reporters.ToList(),
                        UniqueTitle   = a.Art.UniqueTitle,
                        ArticleStatus = a.Art.ArticleStatus,
                    }).ToList()
                };

                foreach (var art in weekList.Articles)
                {
                    var hlAll = _articleHighlightAllRepository.Find(art.Id);
                    var hlCat = _articleHighlightCatRepository.Find(art.Id);

                    art.IsHighlightAll = hlAll == null ? false : true;
                    art.IsHighlightCat = hlCat == null ? false : true;
                    var firstWeekReport = _articleRepository.GetFirstWeekReport(art.Id);
                    var allTimeReport   = _articleRepository.GetAllTimeReport(art.Id);
                    art.AllTimeCount   = allTimeReport.PageView;
                    art.FirstWeekCount = firstWeekReport.PageView;
                }

                publishedList.Add(weekList);
                startDate = endDate.AddDays(1);
            }

            view.PublishedList = publishedList;

            return(View(view));
        }
        public ViewResult Management(DateTime?begin, DateTime?end, int prevnext = 0, int step = 5, string cat = "all", string rep = "", string title = "", int weektab = 0)
        {
            var now           = DateTime.Now;
            var articlesQuery = _articleRepository.GetMany(art => art.ArticleStatus > 0, art => art.PublishedTime);

            if (begin == null || end == null)
            {
                end   = Utilities.GetLastDateOfWeek(now, DayOfWeek.Sunday);
                begin = end.Value.AddDays(-7 * step).AddDays(1);
            }
            else
            {
                if (prevnext == 0)
                {
                    end   = Utilities.GetLastDateOfWeek(now, DayOfWeek.Sunday);
                    begin = end.Value.AddDays(-7 * step);
                }
                else if (prevnext == -1)
                {
                    end   = Utilities.GetFirstDateOfWeek(begin.Value, DayOfWeek.Monday).AddDays(-1);
                    begin = end.Value.AddDays(-7 * step).AddDays(1);
                }
                else if (prevnext == 1)
                {
                    begin = Utilities.GetLastDateOfWeek(end.Value, DayOfWeek.Sunday).AddDays(1);
                    end   = begin.Value.AddDays(7 * step);
                }
            }
            articlesQuery = articlesQuery.Where(v => v.PublishedTime.HasValue && v.PublishedTime.Value.Date >= begin && v.PublishedTime.Value.Date <= end);

            int catId;

            if (cat != "all" && int.TryParse(cat, out catId))
            {
                articlesQuery = articlesQuery.Where(v => v.Categories.Any(c => c.Id == catId));
            }

            if (rep != "")
            {
                articlesQuery = articlesQuery.Where(v => v.Reporters.Any(r => r.Name.Contains(rep)));
            }

            if (title != "")
            {
                articlesQuery = articlesQuery.Where(v => v.Title.Contains(title));
            }

            var startDate = begin.Value;
            var endDate   = end.Value;
            var list      = new List <ArticleCustomDateView>();

            for (int i = 0; i < 5; i++)
            {
                endDate = startDate.AddDays(6);
                var view = new ArticleCustomDateView
                {
                    Week      = cal.GetWeekOfYear(startDate, System.Globalization.CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday),
                    StartDate = startDate,
                    EndDate   = endDate,
                    Articles  = articlesQuery.Where(art => art.PublishedTime.HasValue && art.PublishedTime.Value.Date >= startDate && art.PublishedTime.Value.Date <= endDate)
                                .GroupJoin(_articleSeriesRepository.All, art => art.ArticleSeriesId, asr => asr.Id, (art, asr) => new { Art = art, Srs = asr })
                                .SelectMany(xy => xy.Srs.DefaultIfEmpty(), (x, y) => new { Art = x.Art, Srs = y })
                                .Select(a => new ArticleCustomView()
                    {
                        Id            = a.Art.Id,
                        ArticleName   = a.Art.Title,
                        SeriesName    = a.Srs != null && a.Srs.Articles.Count > 0 ? a.Srs.Name : "",
                        SeriesId      = a.Srs != null ? a.Srs.Id : 0,
                        IsPublished   = a.Art.IsPublished,
                        Order         = a.Art.Order,
                        PublishedTime = a.Art.PublishedTime,
                        Thumbnail     = a.Art.Thumbnail,
                        CatThumbnail  = a.Art.Categories.Count > 0? a.Art.Categories.ElementAt(0).ProfilePhoto:"",
                        CatName       = String.Join(", ", a.Art.Categories.OrderBy(r => r.Order).Select(r => r.Name)),
                        Reporters     = a.Art.Reporters.ToList(),
                        UniqueTitle   = a.Art.UniqueTitle,
                        ArticleStatus = a.Art.ArticleStatus,
                    }).ToList()
                };

                foreach (var art in view.Articles)
                {
                    var hlAll = _articleHighlightAllRepository.Find(art.Id);
                    var hlCat = _articleHighlightCatRepository.Find(art.Id);

                    art.IsHighlightAll = hlAll == null ? false : true;
                    art.IsHighlightCat = hlCat == null ? false : true;
                    var firstWeekReport = _articleRepository.GetFirstWeekReport(art.Id);
                    var allTimeReport   = _articleRepository.GetAllTimeReport(art.Id);
                    art.AllTimeCount   = allTimeReport.PageView;
                    art.FirstWeekCount = firstWeekReport.PageView;
                }

                list.Add(view);
                startDate = endDate.AddDays(1);
            }

            var filterView = new ArticleFilterView
            {
                Category       = cat,
                Reporter       = rep,
                Title          = title,
                Begin          = begin,
                End            = end,
                CustomArticles = list
            };

            ViewBag.weektab    = weektab;
            ViewBag.ArticleCat = _articleCategoryRepository.All.ToList();
            return(View(filterView));
        }