示例#1
0
        /// <summary>
        /// Gets the planned hours for ths item at a given planning.
        /// </summary>
        /// <remarks>If there is no hours planned at the planning number, returns the last planning.</remarks>
        /// <param name="planningNumber">The planning number.</param>
        /// <returns>The planned hours</returns>
        public List <PlannedHour> GetPlannedHoursAtPlanning(int planningNumber)
        {
            if (PlannedHours == null || PlannedHours.Count == 0)
            {
                return(null);
            }

            if (planningNumber < 0)
            {
                planningNumber = 0;
            }

            // this is wrong
            //if(planningNumber >= PlanningNumber)
            //    return PlannedHours.Where(p => p.PlanningNumber == PlanningNumber).ToList();

            // gets the last planning minor then planningNumber
            ICollection <PlannedHour> previousPlans = PlannedHours.Where(h => h.PlanningNumber <= planningNumber).ToArray();

            if (previousPlans == null || previousPlans.Count == 0)
            {
                return(null);
            }
            int lastPlan = previousPlans.Max(h => h.PlanningNumber);

            return(PlannedHours.Where(p => p.PlanningNumber == lastPlan).ToList());
        }
示例#2
0
        public List <PlannedHour> GetValidPlannedHours()
        {
            if (PlannedHours == null || PlannedHours.Count == 0)
            {
                return(null);
            }

            // gets the last planning minor then planningNumber
            return(PlannedHours.Where(h =>
                                      h.SprintNumber >= h.PlanningNumber &&
                                      !PlannedHours.Any(h2 => h2 != h && h2.PlanningNumber > h.PlanningNumber && h2.PlanningNumber <= h.SprintNumber)).ToList());
        }
示例#3
0
        /// <summary>
        /// Sync the planned hours collection of the item with the roles of the project.
        /// </summary>
        public void SyncPlannedHoursAndRoles(int?sprintNumber)
        {
            if (Project == null)
            {
                throw new System.Exception("Can not change a item sprint that is not linked to a project");
            }

            if (Project.Roles == null)
            {
                throw new System.Exception("Can not change a item sprint that is not linked to project roles");
            }

            if (PlannedHours == null)
            {
                PlannedHours = new List <PlannedHour>();
            }

            int maxItemPlan = Project.CurrentPlanningNumber;

            if (PlannedHours.Count > 0)
            {
                maxItemPlan = PlannedHours.Max(p => p.PlanningNumber);
            }

            foreach (Role r in Project.Roles)
            {
                PlannedHour hour = PlannedHours.SingleOrDefault(h => h.RoleUId == r.RoleUId);
                if (hour == null)
                {
                    PlannedHours.Add(new PlannedHour()
                    {
                        Role           = r,
                        RoleUId        = r.RoleUId,
                        PlanningNumber = maxItemPlan,
                        SprintNumber   = sprintNumber,
                        BacklogItemUId = this.BacklogItemUId,
                        Hours          = 0
                    });
                }
                else
                {
                    hour.Role = r;
                }
            }

            PlannedHour[] deletedHours = PlannedHours.Where(h => !Project.Roles.Any(r => r.RoleUId == h.RoleUId)).ToArray();
            for (int i = deletedHours.Length - 1; i >= 0; i--)
            {
                PlannedHours.Remove(deletedHours[i]);
            }
        }