コード例 #1
0
        public PtDashboardFilteredIssues GetFilteredIssues(PtDashboardFilter filter)
        {
            var openItemSpec   = new PtItemStatusSpecification(StatusEnum.Open);
            var closedItemSpec = new PtItemStatusSpecification(StatusEnum.Closed);

            var userIdSpec    = new PtItemUserIdSpecification(filter.UserId);
            var dateRangeSpec = new PtItemDateRangeSpecification(filter.DateStart, filter.DateEnd);

            //var items = Find(userIdSpec.And(dateRangeSpec));

            var itemsForUserAndDates = context.PtItems
                                       .Where(userIdSpec.ToExpression().Compile())
                                       .Where(dateRangeSpec.ToExpression().Compile());

            var minDate = itemsForUserAndDates.Min(i => i.DateCreated);
            var maxDate = itemsForUserAndDates.Max(i => i.DateCreated);

            var categories = GetDates(minDate, maxDate);

            var itemsByMonth = categories.Select(c => {
                return(itemsForUserAndDates.Where(i => {
                    var dc = i.DateCreated;
                    return dc.Month == c.Month && dc.Year == c.Year;
                }));
            });


            var categorizedAndDivided = itemsByMonth.Select(c => {
                var openItemsForMonth   = c.Where(openItemSpec.ToExpression().Compile()).ToList();
                var closedItemsForMonth = c.Where(closedItemSpec.ToExpression().Compile()).ToList();

                return(new ItemsForMonth
                {
                    Open = openItemsForMonth,
                    Closed = closedItemsForMonth
                });
            });

            var issues = new PtDashboardFilteredIssues
            {
                Categories = categories,
                MonthItems = categorizedAndDivided.ToList()
            };

            return(issues);
        }
コード例 #2
0
        public PtDashboardVm(PtDashboardStatusCounts statusCounts, PtDashboardFilteredIssues filteredIssues, List <PtUser> users, int?userId)
        {
            IssueCountOpen   = statusCounts.OpenItemsCount;
            IssueCountClosed = statusCounts.ClosedItemsCount;

            ItemsOpenByMonth   = new List <int>();
            ItemsClosedByMonth = new List <int>();
            Categories         = new List <DateTime>();

            filteredIssues.MonthItems.ForEach(i => {
                ItemsOpenByMonth.Add(i.Open.Count);
                ItemsClosedByMonth.Add(i.Closed.Count);
            });
            Categories = filteredIssues.Categories;

            Assignees = users;
            if (userId.HasValue)
            {
                SelectedAssigneeId = userId.Value;
            }
        }