Ejemplo n.º 1
0
        /// <summary>
        /// Gets all work items of the type provided by T, and then filters, sorts and pages the list using the parameters provided.
        /// </summary>
        protected ListData FilterAndPage <T>(FilterOptions filterOptions, string projectName, string sortBy, bool?descending, int?page, int?pageSize)
            where T : WorkItemSummary, new()
        {
            QueryManager <T> manager = new QueryManager <T>();

            if (!string.IsNullOrEmpty(projectName))
            {
                if (projectName != UserContext.Current.CurrentProject.Name)
                {
                    UserContext.Current.ChangeCurrentProject(projectName);
                }
            }

            if (!string.IsNullOrEmpty(filterOptions.Title))
            {
                manager.WithTitle(filterOptions.Title);
            }

            if (!string.IsNullOrEmpty(filterOptions.AssignedTo))
            {
                manager.AndAssignedTo(filterOptions.AssignedTo);
            }

            //
            // Status
            //
            if (filterOptions.Active)
            {
                manager.WhereActive();
            }
            else if (filterOptions.Closed)
            {
                manager.WhereClosed();
            }
            else if (filterOptions.Resolved)
            {
                manager.WhereResolved();
            }

            //
            // Dates
            //
            if (filterOptions.StartDate > DateTime.MinValue)
            {
                manager.WithStartingFromDate(filterOptions.StartDate);
            }

            if (filterOptions.EndDate > DateTime.MinValue)
            {
                manager.WithEndingOnDate(filterOptions.EndDate);
            }

            IEnumerable <WorkItemSummary> list = manager.Execute();

            ListData data = new ListData();

            data.FilterValues.Title      = filterOptions.Title;
            data.FilterValues.AssignedTo = filterOptions.AssignedTo;
            data.FilterValues.Status     = filterOptions.ConvertStatusToString();
            data.WorkItems = list;

            if (filterOptions.StartDate > DateTime.MinValue)
            {
                data.FilterValues.StartDate = filterOptions.StartDate.ToShortDateString();
            }
            else
            {
                data.FilterValues.StartDate = "";
            }

            if (filterOptions.EndDate > DateTime.MinValue)
            {
                data.FilterValues.EndDate = filterOptions.StartDate.ToShortDateString();
            }
            else
            {
                data.FilterValues.EndDate = "";
            }


            PageList(data, sortBy, descending, page, pageSize);

            return(data);
        }