public async Task <Opportunity> UpdateWorkflowAsync(Opportunity opportunity, string requestId = "") { try { var initialState = opportunity.Metadata.OpportunityState; //create team and channels if (opportunity.Content.DealType.ProcessList != null && opportunity.Metadata.OpportunityState == OpportunityState.Creating) { if (await GroupIdCheckAsync(opportunity.DisplayName, requestId)) { string generalChannelId = await CreateTeamAndChannelsAsync(opportunity, requestId); //Temperary change, will revert to back after implementing "add app" opportunity.Metadata.OpportunityState = OpportunityState.InProgress; //set channelId for Bot notifications. opportunity.Metadata.OpportunityChannelId = generalChannelId; } } else if (opportunity.Metadata.OpportunityState == OpportunityState.Creating) { // QUESTION: why are we trying to add the RelationshipManager when he was already added in the CreateWorkflowAsync? Also this shouldn't // be run on every update, only when the opportunity is being created and the LO is assigned (or updated) // ONLY add LoanOfficer //Adding RelationShipManager and LoanOfficer into ProposalManager Team var loanOfficer = opportunity.Content.TeamMembers.FirstOrDefault(item => item.AssignedRole.DisplayName.Equals("LoanOfficer", StringComparison.OrdinalIgnoreCase)); if (loanOfficer != null) { try { var options = new List <QueryParam>() { new QueryParam("filter", $"startswith(displayName,'{_appOptions.GeneralProposalManagementTeam}')") }; dynamic jsonDyn = await _graphUserAppService.GetGroupAsync(options, "", requestId); if (!string.IsNullOrEmpty(jsonDyn.value[0].id.ToString()) && !string.IsNullOrEmpty(loanOfficer.Fields.UserPrincipalName)) { try { var groupID = jsonDyn.value[0].id.ToString(); Guard.Against.NullOrEmpty(loanOfficer.Id, $"OpportunityFactorty_{loanOfficer.AssignedRole.DisplayName} Id NullOrEmpty", requestId); await _graphUserAppService.AddGroupMemberAsync(loanOfficer.Id, groupID, requestId); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - userId: {loanOfficer.Id} - OpportunityFactorty_AddGroupMemberAsync_{loanOfficer.AssignedRole.DisplayName} error in CreateWorkflowAsync: {ex}"); } } } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - userId: {loanOfficer.Id} - OpportunityFactorty_AddGroupMemberAsync_{loanOfficer.AssignedRole.DisplayName} error in CreateWorkflowAsync: {ex}"); } } } bool checklistPass = false; if (opportunity.Metadata.OpportunityState != OpportunityState.Creating) { try { opportunity = await MoveTempFileToTeamAsync(opportunity, requestId); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - UpdateWorkflowAsync_MoveTempFileToTeam Service Exception: {ex}"); } if (opportunity.Content.DealType.ProcessList != null) { foreach (var item in opportunity.Content.DealType.ProcessList) { if (item.ProcessType.Equals("checklisttab", StringComparison.OrdinalIgnoreCase) && checklistPass == false) { //DashBoard Create call Start. await UpdateDashBoardEntryAsync(opportunity, requestId); //DashBoard Create call End. opportunity = await _checkListProcessService.UpdateWorkflowAsync(opportunity, requestId); checklistPass = true; } else if (item.ProcessType.Equals("customerdecisiontab", StringComparison.OrdinalIgnoreCase)) { opportunity = await _customerDecisionProcessService.UpdateWorkflowAsync(opportunity, requestId); } else if (item.ProcessType.Equals("proposalstatustab", StringComparison.OrdinalIgnoreCase)) { opportunity = await _proposalStatusProcessService.UpdateWorkflowAsync(opportunity, requestId); } else if (item.ProcessStep.Equals("start process", StringComparison.OrdinalIgnoreCase)) { opportunity = await _startProcessService.UpdateWorkflowAsync(opportunity, requestId); } else if (item.ProcessStep.Equals("new opportunity", StringComparison.OrdinalIgnoreCase)) { opportunity = await _newOpportunityProcessService.UpdateWorkflowAsync(opportunity, requestId); } } } } // Send notification _logger.LogInformation($"RequestId: {requestId} - UpdateWorkflowAsync initialState: {initialState.Name} - {opportunity.Metadata.OpportunityState.Name}"); if (initialState.Value != opportunity.Metadata.OpportunityState.Value) { try { _logger.LogInformation($"RequestId: {requestId} - CreateWorkflowAsync sendNotificationCardAsync opportunity state change notification."); await _cardNotificationService.sendNotificationCardAsync(opportunity, UserProfile.Empty, $"Opportunity state for {opportunity.DisplayName} has been changed to {opportunity.Metadata.OpportunityState.Name}", requestId); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - CreateWorkflowAsync sendNotificationCardAsync OpportunityState error: {ex}"); } } return(opportunity); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - UpdateWorkflowAsync Service Exception: {ex}"); throw new ResponseException($"RequestId: {requestId} - UpdateWorkflowAsync Service Exception: {ex}"); } }
public async Task <Opportunity> UpdateWorkflowAsync(Opportunity opportunity, string requestId = "") { try { var initialState = opportunity.Metadata.OpportunityState; //create team and channels if (opportunity.Content.DealType.ProcessList != null && opportunity.Metadata.OpportunityState == OpportunityState.Creating) { if (await GroupIdCheckAsync(opportunity.DisplayName, requestId)) { string generalChannelId = await CreateTeamAndChannelsAsync(opportunity, requestId); //Temperary change, will revert to back after implementing "add app" opportunity.Metadata.OpportunityState = OpportunityState.InProgress; //set channelId for Bot notifications. opportunity.Metadata.OpportunityChannelId = generalChannelId; } } bool checklistPass = false; if (opportunity.Metadata.OpportunityState != OpportunityState.Creating) { try { opportunity = await MoveTempFileToTeamAsync(opportunity, requestId); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - UpdateWorkflowAsync_MoveTempFileToTeam Service Exception: {ex}"); } if (opportunity.Content.DealType.ProcessList != null) { foreach (var item in opportunity.Content.DealType.ProcessList) { if (item.ProcessType.ToLower() == "checklisttab" && checklistPass == false) { //DashBoard Create call Start. await UpdateDashBoardEntryAsync(opportunity, requestId); //DashBoard Create call End. opportunity = await _checkListProcessService.UpdateWorkflowAsync(opportunity, requestId); checklistPass = true; } else if (item.ProcessType.ToLower() == "customerdecisiontab") { opportunity = await _customerDecisionProcessService.UpdateWorkflowAsync(opportunity, requestId); } else if (item.ProcessType.ToLower() == "proposalstatustab") { opportunity = await _proposalStatusProcessService.UpdateWorkflowAsync(opportunity, requestId); } else if (item.ProcessStep.ToLower() == "start process") { opportunity = await _startProcessService.UpdateWorkflowAsync(opportunity, requestId); } else if (item.ProcessStep.ToLower() == "new opportunity") { opportunity = await _newOpportunityProcessService.UpdateWorkflowAsync(opportunity, requestId); } } } var roleMappings = (await _roleMappingRepository.GetAllAsync(requestId)).ToList(); } // Send notification _logger.LogInformation($"RequestId: {requestId} - UpdateWorkflowAsync initialState: {initialState.Name} - {opportunity.Metadata.OpportunityState.Name}"); if (initialState.Value != opportunity.Metadata.OpportunityState.Value) { try { _logger.LogInformation($"RequestId: {requestId} - CreateWorkflowAsync sendNotificationCardAsync opportunity state change notification."); var sendTo = UserProfile.Empty; var sendNotificationCard = await _cardNotificationService.sendNotificationCardAsync(opportunity, sendTo, $"Opportunity state for {opportunity.DisplayName} has been changed to {opportunity.Metadata.OpportunityState.Name}", requestId); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - CreateWorkflowAsync sendNotificationCardAsync OpportunityState error: {ex}"); } } //Adding RelationShipManager and LoanOfficer into ProposalManager Team foreach (var item in opportunity.Content.TeamMembers) { try { if (item.AssignedRole.DisplayName == "LoanOfficer" || item.AssignedRole.DisplayName == "RelationshipManager") { dynamic jsonDyn = null; var options = new List <QueryParam>(); options.Add(new QueryParam("filter", $"startswith(displayName,'Proposal Manager Team')")); var groupIdJson = await _graphUserAppService.GetGroupAsync(options, "", requestId); jsonDyn = groupIdJson; if (!String.IsNullOrEmpty(jsonDyn.value[0].id.ToString())) { var groupID = jsonDyn.value[0].id.ToString(); if (!String.IsNullOrEmpty(item.Fields.UserPrincipalName)) { try { Guard.Against.NullOrEmpty(item.Id, $"OpportunityFactorty_{item.AssignedRole.DisplayName} Id NullOrEmpty", requestId); var responseJson = await _graphUserAppService.AddGroupMemberAsync(item.Id, groupID, requestId); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - userId: {item.Id} - OpportunityFactorty_AddGroupMemberAsync_{item.AssignedRole.DisplayName} error in CreateWorkflowAsync: {ex}"); } } } } } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - userId: {item.Id} - OpportunityFactorty_AddGroupMemberAsync_{item.AssignedRole.DisplayName} error in CreateWorkflowAsync: {ex}"); } } //Adding RelationShipManager and LoanOfficer into ProposalManager Team return(opportunity); } catch (Exception ex) { _logger.LogError($"RequestId: {requestId} - UpdateWorkflowAsync Service Exception: {ex}"); throw new ResponseException($"RequestId: {requestId} - UpdateWorkflowAsync Service Exception: {ex}"); } }