public async Task<IList<BuildDefinition>> GetBuildDefinitions(AccountDetails accountDetails)
 {
     _restClient.SetBasicCredentials(accountDetails.EncodedCredentials);
     string address = VsoAddressHelper.GetFullAddress(accountDetails.AccountName, string.Format(Constants.VsoBuildDefinitionsAddress, accountDetails.ProjectId));
     VsoBuildDefinitionList buildList = await _restClient.GetRequest<VsoBuildDefinitionList>(null, address);
     return buildList.Value.Select(build => _mapper.MapToBuildDefinition(build)).ToList();
 }
 public async Task<IList<Project>> GetProjects(AccountDetails accountDetails)
 {
     _restClient.SetBasicCredentials(accountDetails.EncodedCredentials);
     string address = VsoAddressHelper.GetFullAddress(accountDetails.AccountName,  Constants.VsoProjectsAddress);
     VsoProjectList projectList = await _restClient.GetRequest<VsoProjectList>(null, address);
     return projectList.Value.Select(project => _mapper.MapToProject(project)).ToList();
 }
 public async Task<IList<Model.Build>> GetBuilds(AccountDetails accountDetails, IList<string> buildDefinitions)
 {
     _restClient.SetBasicCredentials(accountDetails.EncodedCredentials);
     string formattedBuildDefinitions = string.Join(",", buildDefinitions);
     
     string address = VsoAddressHelper.GetFullAddress(accountDetails.AccountName, string.Format(Constants.VsoBuildsAddress, accountDetails.ProjectId, formattedBuildDefinitions, NumberOfBuildsToCheck));
     Model.DTO.VsoBuildList buildList = await _restClient.GetRequest<Model.DTO.VsoBuildList>(null, address);
     return buildList.Value.Select(record => _mapper.MapToBuild(record)).ToList();
 }
        public async Task UpdateAccount(Account account)
        {
            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }

            IList<Account> existingAccounts = GetAccounts();
            
            AccountDetails accountDetails = new AccountDetails
            {
                AccountName = account.Name,
                EncodedCredentials = account.EncodedCredentials
            };

            // Get any updates to projects and builds
            account.Projects = await _vsoClient.GetProjects(accountDetails);

            foreach (Project vsoProject in account.Projects)
            {
                accountDetails.ProjectId = vsoProject.Id;
                vsoProject.Builds = await _vsoClient.GetBuildDefinitions(accountDetails);
                vsoProject.Builds.ToList().ForEach(b => b.IsSelected = false);
            }

            // Replace existing reference to account if there is one
            Account existingAccount = existingAccounts.SingleOrDefault(a => a.Name == account.Name);

            if (existingAccount == null)
            {
                existingAccounts.Add(account);
            }
            else
            {
                TransferSubscriptions(existingAccount, account); // todo - be careful that all data is transferred + new builds / projects included
                int indexOfExistingAccount = existingAccounts.IndexOf(existingAccount);
                existingAccounts[indexOfExistingAccount] = account;
            }

            SaveAccounts(existingAccounts);
        }