private async Task AddEnvironmentIfNotExistsAsync(IList <EnvironmentDto> environmentCollection, string environment) { if (!environmentCollection.Any(x => x.Name == environment)) { await _environmentRepository.InsertAsync(new EnvironmentDto { Name = environment }); } }
private async Task ProcessEnvironments(SyncJobCompositeModel syncJobCompositeModel, SpaceModel space) { await LogInformation($"Getting all the environments for {syncJobCompositeModel.InstanceModel.Name}:{space.Name}", syncJobCompositeModel); var octopusList = await _octopusRepository.GetAllEnvironmentsForSpaceAsync(syncJobCompositeModel.InstanceModel, space); await LogInformation($"{octopusList.Count} environments(s) found in {syncJobCompositeModel.InstanceModel.Name}:{space.Name}", syncJobCompositeModel); foreach (var item in octopusList) { await LogInformation($"Checking to see if environment {item.OctopusId}:{item.Name} already exists", syncJobCompositeModel); var itemModel = await _environmentRepository.GetByOctopusIdAsync(item.OctopusId, space.Id); await LogInformation($"{(itemModel != null ? "Environment already exists, updating" : "Unable to find environment, creating")}", syncJobCompositeModel); item.Id = itemModel?.Id ?? 0; await LogInformation($"Saving environment {item.OctopusId}:{item.Name} to the database", syncJobCompositeModel); var modelToTrack = item.Id > 0 ? await _environmentRepository.UpdateAsync(item) : await _environmentRepository.InsertAsync(item); await LogInformation($"Adding environment {item.OctopusId}:{item.Name} to our sync dictionary for faster lookup", syncJobCompositeModel); syncJobCompositeModel.EnvironmentDictionary.Add(item.OctopusId, modelToTrack); } }
public Task <EnvironmentModel> Insert(int spaceId, EnvironmentModel model) { model.SpaceId = spaceId; return(_repository.InsertAsync(model)); }