public void SetSelectedProject(int projectId)
 {
     if (_flatProjects != null)
     {
         SelectedProject = _flatProjects.Where(p => p.Id == projectId).FirstOrDefault();
     }
 }
        private List <ProjectViewModel> LoadProjectsFromRedmine()
        {
            var projectsList = new List <ProjectViewModel>();

            IList <Net.Api.Types.Project> projects = null;

            try
            {
                // connect to redmine
                Net.Api.RedmineManager manager = new Net.Api.RedmineManager(Settings.Default.RedmineServer, Settings.Default.RedmineApi, Net.Api.MimeFormat.xml);
                var parameters = new NameValueCollection {
                    { "limit", "100" }, { "include", "trackers,issue_categories" }
                };

                projects = GetAllRecords <Net.Api.Types.Project>(manager, parameters);
            }
            catch { }

            if (projects == null)
            {
                return(null);
            }

            foreach (var project in projects)
            {
                ProjectViewModel projectViewModel = new ProjectViewModel
                {
                    Id   = project.Id,
                    Name = project.Name
                };

                if (project.Parent != null)
                {
                    projectViewModel.ParentId = project.Parent.Id;
                }

                if (project.CustomFields != null)
                {
                    foreach (var customField in project.CustomFields)
                    {
                        CustomFieldViewModel customFieldViewModel = new CustomFieldViewModel
                        {
                            Id   = customField.Id,
                            Name = customField.Name
                        };

                        projectViewModel.CustomFields.Add(customFieldViewModel);
                    }
                }

                if (project.Trackers != null)
                {
                    foreach (var tracker in project.Trackers)
                    {
                        TrackerViewModel trackerViewModel = new TrackerViewModel
                        {
                            Id   = tracker.Id,
                            Name = tracker.Name
                        };

                        projectViewModel.Trackers.Add(trackerViewModel);

                        // set first one as default
                        if (projectViewModel.Tracker == null)
                        {
                            projectViewModel.Tracker = trackerViewModel;
                        }
                    }
                }

                if (project.IssueCategories != null)
                {
                    foreach (var issueCategory in project.IssueCategories)
                    {
                        IssueCategoryViewModel issueCategoryViewModel = new IssueCategoryViewModel
                        {
                            Id   = issueCategory.Id,
                            Name = issueCategory.Name
                        };

                        projectViewModel.IssueCategories.Add(issueCategoryViewModel);
                    }
                }

                projectsList.Add(projectViewModel);
            }

            return(projectsList);
        }
        private List<ProjectViewModel> LoadProjectsFromRedmine()
        {
            var projectsList = new List<ProjectViewModel>();

            IList<Net.Api.Types.Project> projects = null;
            try
            {
                // connect to redmine
                Net.Api.RedmineManager manager = new Net.Api.RedmineManager(Settings.Default.RedmineServer, Settings.Default.RedmineApi, Net.Api.MimeFormat.xml);

                projects = manager.GetObjectList<Net.Api.Types.Project>(new System.Collections.Specialized.NameValueCollection { { "limit", "100" }, { "include", "trackers,issue_categories" } });
            }
            catch { }

            if (projects == null)
            {
                return null;
            }

            foreach (var project in projects)
            {
                ProjectViewModel projectViewModel = new ProjectViewModel();
                projectViewModel.Id = project.Id;
                projectViewModel.Name = project.Name;
                if (project.Parent != null)
                {
                    projectViewModel.ParentId = project.Parent.Id;
                }

                if (project.CustomFields != null)
                {
                    foreach (var customField in project.CustomFields)
                    {
                        CustomFieldViewModel customFieldViewModel = new CustomFieldViewModel();
                        customFieldViewModel.Id = customField.Id;
                        customFieldViewModel.Name = customField.Name;

                        projectViewModel.CustomFields.Add(customFieldViewModel);
                    }
                }

                if (project.Trackers != null)
                {
                    foreach (var tracker in project.Trackers)
                    {
                        TrackerViewModel trackerViewModel = new TrackerViewModel();
                        trackerViewModel.Id = tracker.Id;
                        trackerViewModel.Name = tracker.Name;

                        projectViewModel.Trackers.Add(trackerViewModel);

                        // set first one as default
                        if (projectViewModel.Tracker == null)
                        {
                            projectViewModel.Tracker = trackerViewModel;
                        }
                    }
                }

                if (project.IssueCategories != null)
                {
                    foreach (var issueCategory in project.IssueCategories)
                    {
                        IssueCategoryViewModel issueCategoryViewModel = new IssueCategoryViewModel();
                        issueCategoryViewModel.Id = issueCategory.Id;
                        issueCategoryViewModel.Name = issueCategory.Name;

                        projectViewModel.IssueCategories.Add(issueCategoryViewModel);
                    }
                }

                projectsList.Add(projectViewModel);
            }

            return projectsList;
        }