private async Task <string> CreateTeamAndChannelsAsync(Opportunity opportunity, string requestId = "") { _logger.LogError($"RequestId: {requestId} - createTeamAndChannels Started"); try { //create team var responce = await _graphTeamsAppService.CreateTeamAsync(opportunity.DisplayName, requestId); var groupID = responce["id"].ToString(); //Get general channel id dynamic generalChannelObj = await _graphTeamsAppService.ListChannelAsync(groupID); string generalChannelId = generalChannelObj.value[0].id.ToString(); foreach (var process in opportunity.Content.DealType.ProcessList.Where(x => !x.Channel.Equals("none", StringComparison.OrdinalIgnoreCase))) { await _graphTeamsAppService.CreateChannelAsync(groupID, process.Channel, process.Channel + " Channel"); } try { //Vault is no longer using so we will comment out this in the near future Guard.Against.NullOrEmpty(await _azureKeyVaultService.GetValueFromVaultAsync(VaultKeys.Upn), "CreateWorkflowAsync_Admin_Ups Null or empty", requestId); var responseJson = await _graphUserAppService.AddGroupOwnerAsync(await _azureKeyVaultService.GetValueFromVaultAsync(VaultKeys.Upn), groupID); var response = await _graphUserAppService.AddGroupMemberAsync(await _azureKeyVaultService.GetValueFromVaultAsync(VaultKeys.Upn), groupID); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - CreateTeamAndChannels_AddAppToTeamAsync Service Exception: {ex}"); } // Invoke Dynamics webhook setup // TODO: this condition is temporarly added to the OpportunityFactory in order to avoid invoking the DynamicsController unless the Dynamics configuration // if available, otherwise it blows up in the ctor. if (!string.IsNullOrWhiteSpace(opportunity.Reference)) { try { // Call to AddIn helper once team has been created await _addInHelper.CallAddInWebhookAsync(opportunity, requestId); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} -_addInHelper.CallAddInWebhookAsync(opportunity, requestId): {ex}"); } } // Activate Document Id Service await _addInHelper.ActivateDocumentId(opportunity); return(generalChannelId); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - CreateTeamAndChannels Service Exception: {ex}"); throw new ResponseException($"RequestId: {requestId} - CreateTeamAndChannels Service Exception: {ex}"); } }
private async Task <string> CreateTeamAndChannelsAsync(Opportunity opportunity, string requestId = "") { _logger.LogError($"RequestId: {requestId} - createTeamAndChannels Started"); try { //create team var responce = await _graphTeamsAppService.CreateTeamAsync(opportunity.DisplayName, requestId); //get Group ID bool check = true; dynamic jsonDyn = null; var opportunityName = WebUtility.UrlEncode(opportunity.DisplayName); var options = new List <QueryParam>(); options.Add(new QueryParam("filter", $"startswith(displayName,'{opportunityName}')")); while (check) { var groupIdJson = await _graphUserAppService.GetGroupAsync(options, "", requestId); jsonDyn = groupIdJson; JArray jsonArray = JArray.Parse(jsonDyn["value"].ToString()); if (jsonArray.Count() > 0) { if (!String.IsNullOrEmpty(jsonDyn.value[0].id.ToString())) { check = false; } } } var groupID = String.Empty; groupID = jsonDyn.value[0].id.ToString(); //Get general channel id var generalChannel = await _graphTeamsAppService.ListChannelAsync(groupID); dynamic generalChannelObj = generalChannel; string generalChannelId = generalChannelObj.value[0].id.ToString(); foreach (var process in opportunity.Content.DealType.ProcessList) { if (process.Channel.ToLower() != "none") { await _graphTeamsAppService.CreateChannelAsync(groupID, process.Channel, process.Channel + " Channel"); } } //adding app is currently not supported this code is there so that we can add the app to the team once //graph api supports usercontext for this functionality try { //Vault is no longer using so we will comment out this in the near future Guard.Against.NullOrEmpty(await _azureKeyVaultService.GetValueFromVaultAsync(VaultKeys.Upn), "CreateWorkflowAsync_Admin_Ups Null or empty", requestId); var responseJson = await _graphUserAppService.AddGroupOwnerAsync(await _azureKeyVaultService.GetValueFromVaultAsync(VaultKeys.Upn), groupID); var response = await _graphUserAppService.AddGroupMemberAsync(await _azureKeyVaultService.GetValueFromVaultAsync(VaultKeys.Upn), groupID); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - CreateTeamAndChannels_AddAppToTeamAsync Service Exception: {ex}"); } //adding addin to the app try { await _graphTeamsOnBehalfService.AddAppToTeamAsync(groupID); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - CreateTeamAndChannels_AddAppToTeamAsync Service Exception: {ex}"); } // Invoke Dynamics webhook setup // TODO: this condition is temporarly added to the OpportunityFactory in order to avoid invoking the DynamicsController unless the Dynamics configuration // if available, otherwise it blows up in the ctor. if (!string.IsNullOrWhiteSpace(opportunity.Reference)) { try { // Call to AddIn helper once team has been created await _addInHelper.CallAddInWebhookAsync(opportunity, requestId); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} -_addInHelper.CallAddInWebhookAsync(opportunity, requestId): {ex}"); } } // Activate Document Id Service await _addInHelper.ActivateDocumentId(opportunity); return(generalChannelId); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - CreateTeamAndChannels Service Exception: {ex}"); throw new ResponseException($"RequestId: {requestId} - CreateTeamAndChannels Service Exception: {ex}"); } }