Esempio n. 1
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]);
            }
        }