示例#1
0
        public ActionResult Preferences()
        {
            var model = new PreferencesModel();

            var projectsDto   = _teamCityApi.GetAllProjects();
            var buildTypesDto = _teamCityApi.GetAllBuildTypes();

            if (projectsDto == null || buildTypesDto == null)
            {
                return(View(model));
            }

            foreach (var project in projectsDto.Project)
            {
                model.Projects.Add(new ProjectModel
                {
                    Id         = project.Id,
                    Name       = project.Name,
                    BuildTypes = buildTypesDto.BuildType
                                 .Where(b => b.ProjectId == project.Id)
                                 .Select(p => new BuildTypeModel {
                        Id = p.Id, Name = p.Name
                    })
                                 .ToList()
                });
            }

            model.HiddenProjects   = _preferencesService.GetHiddenProjects().ToList();
            model.HiddenBuildTypes = _preferencesService.GetHiddenBuildTypes().ToList();
            return(View(model));
        }
示例#2
0
        private Model LoadModel()
        {
            var projectDto       = _apiClient.GetAllProjects();
            var buildTypesDto    = _apiClient.GetAllBuildTypes();
            var hiddenProjects   = _preferencesService.GetHiddenProjects();
            var hiddenBuildTypes = _preferencesService.GetHiddenBuildTypes();


            var model = new Model();

            if (projectDto == null || buildTypesDto == null)
            {
                return(model);
            }

            foreach (var project in projectDto.Project.Where(p => hiddenProjects.All(h => h != p.Id)))
            {
                var buildTypesForProject = buildTypesDto.BuildType
                                           .Where(b => b.ProjectId == project.Id && hiddenBuildTypes.All(h => h != b.Id))
                                           .ToList();

                var buildTypeRows = buildTypesForProject
                                    .Select((p, index) => new { p, index })
                                    .GroupBy(a => a.index / 4)
                                    .Select(grp => grp.Select(g => g.p).ToList())
                                    .ToList();

                var projectModel = new ProjectModel {
                    Name = project.Name, Id = project.Id
                };

                foreach (var buildTypeRow in buildTypeRows)
                {
                    var buildType1 = buildTypeRow.FirstOrDefault();
                    var buildType2 = buildTypeRow.Skip(1).FirstOrDefault();
                    var buildType3 = buildTypeRow.Skip(2).FirstOrDefault();
                    var buildType4 = buildTypeRow.Skip(3).FirstOrDefault();

                    var row = new BuildTypeRow();
                    if (buildType1 != null)
                    {
                        row.BuildTypes.Add(new BuildTypeModel {
                            Name = buildType1.Name, BuildTypeId = buildType1.Id
                        });
                    }
                    if (buildType2 != null)
                    {
                        row.BuildTypes.Add(new BuildTypeModel {
                            Name = buildType2.Name, BuildTypeId = buildType2.Id
                        });
                    }
                    if (buildType3 != null)
                    {
                        row.BuildTypes.Add(new BuildTypeModel {
                            Name = buildType3.Name, BuildTypeId = buildType3.Id
                        });
                    }
                    if (buildType4 != null)
                    {
                        row.BuildTypes.Add(new BuildTypeModel {
                            Name = buildType4.Name, BuildTypeId = buildType4.Id
                        });
                    }

                    projectModel.BuildTypeRows.Add(row);
                }

                model.Projects.Add(projectModel);
            }
            return(model);
        }