public async Task <Opportunity> CreateWorkflowAsync(Opportunity opportunity, string requestId = "") { _logger.LogError($"RequestId: {requestId} - createTeamAndChannels Started"); try { string memberId = String.Empty; if (opportunity.Content.TeamMembers.Any()) { memberId = opportunity.Content.TeamMembers.FirstOrDefault()?.Id; } var groupID = String.Empty; try { var response = await _graphTeamsAppService.CreateTeamAsync(opportunity.DisplayName, memberId, requestId); groupID = response["id"].ToString(); } catch (Exception ex) { throw new ResponseException($"RequestId: {requestId} - CreateWorkflowAsync Service Exception: {ex}"); } var generalChannel = await _graphTeamsAppService.ListChannelAsync(groupID); dynamic generalChannelObj = generalChannel; string generalChannelId = generalChannelObj.value[0].id.ToString(); if (!String.IsNullOrEmpty(generalChannelId)) { opportunity.Metadata.OpportunityChannelId = generalChannelId; } else { throw new ResponseException($"RequestId: {requestId} - CreateWorkflowAsync Service Exception: Opportunity Channel is not created"); } var channelInfo = new List <Tuple <string, string> >(); channelInfo.Add(new Tuple <string, string>("General", generalChannelId)); foreach (var process in opportunity.Content.Template.ProcessList) { if (process.Channel.ToLower() != "none" && process.ProcessType.ToLower() != "none") { var response = await _graphTeamsAppService.CreateChannelAsync(groupID, process.Channel, process.Channel + " Channel"); channelInfo.Add(new Tuple <string, string>(process.Channel, response["id"].ToString())); } } try { await _graphTeamsOnBehalfService.AddAppToTeamAsync(groupID); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - CreateTeamAndChannels_AddAppToTeamAsync Service Exception: {ex}"); } foreach (var channel in channelInfo) { try { await _graphTeamsAppService.AddTab(channel.Item1, groupID, channel.Item2, opportunity.DisplayName, _baseUrl); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - Adding General Tab Service Exception: {ex}"); } } 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(opportunity); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - CreateTeamAndChannels Service Exception: {ex}"); throw new ResponseException($"RequestId: {requestId} - CreateTeamAndChannels Service Exception: {ex}"); } }
private async Task CreateTeamAndChannelsAsync(Opportunity opportunity, string requestId = "") { _logger.LogError($"RequestId: {requestId} - createTeamAndChannels Started"); try { //create team 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(); 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 { await _graphTeamsAppService.AddAppToTeamAsync(groupID); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - CreateTeamAndChannels_AddAppToTeamAsync Service Exception: {ex}"); } try { // Call to AddIn helper once team has been created var resCallAddIn = await _addInHelper.CallAddInWebhookAsync(opportunity, requestId); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} -_addInHelper.CallAddInWebhookAsync(opportunity, requestId): {ex}"); } } 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); 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}"); } }