Ejemplo n.º 1
0
        private async Task <Opportunity> UpdateDealTypeStatus(Opportunity opportunity, string requestId = "")
        {
            var groupID         = string.Empty;
            var opportunityName = WebUtility.UrlEncode(opportunity.DisplayName);
            var options         = new List <QueryParam> {
                new QueryParam("filter", $"startswith(displayName,'{opportunityName}')")
            };

            while (true)
            {
                dynamic jsonDyn = await _graphUserAppService.GetGroupAsync(options, "", requestId);

                JArray jsonArray = JArray.Parse(jsonDyn["value"].ToString());
                if (jsonArray.Count() > 0)
                {
                    if (!string.IsNullOrEmpty(jsonDyn.value[0].id.ToString()))
                    {
                        groupID = jsonDyn.value[0].id.ToString();
                        break;
                    }
                }
            }

            var processStatus = ActionStatus.NotStarted;

            foreach (var item in opportunity.Content.TeamMembers)
            {
                // QUESTION: adding LO as owner always fails because he's added in the create team process
                if (item.AssignedRole.DisplayName.Equals("RelationshipManager", StringComparison.OrdinalIgnoreCase))
                {
                    processStatus = ActionStatus.InProgress;

                    try
                    {
                        Guard.Against.NullOrEmpty(item.Id, $"UpdateWorkflowAsync_{item.AssignedRole.DisplayName} Id NullOrEmpty", requestId);
                        await _graphUserAppService.AddGroupOwnerAsync(item.Id, groupID, requestId);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"RequestId: {requestId} - userId: {item.Id} - UpdateWorkflowAsync_AddGroupOwnerAsync_{item.AssignedRole.DisplayName} error in CreateWorkflowAsync: {ex}");
                    }
                }

                if (item.AssignedRole.DisplayName.Equals("LoanOfficer", StringComparison.OrdinalIgnoreCase))
                {
                    processStatus = ActionStatus.Completed;
                }

                try
                {
                    Guard.Against.NullOrEmpty(item.Id, $"UpdateStartProcessStatus_{item.AssignedRole.DisplayName} Id NullOrEmpty", requestId);
                    await _graphUserAppService.AddGroupMemberAsync(item.Id, groupID, requestId);
                }
                catch (Exception ex)
                {
                    _logger.LogError($"RequestId: {requestId} - userId: {item.Id} - UpdateStartProcessStatus_AddGroupMemberAsync_{item.AssignedRole.DisplayName} error in CreateWorkflowAsync: {ex}");
                }
            }

            // Update process status
            var process = opportunity.Content.DealType.ProcessList.FirstOrDefault(x => x.ProcessStep.Equals("new opportunity", StringComparison.OrdinalIgnoreCase));

            if (process != null)
            {
                process.Status = processStatus;
            }

            return(opportunity);
        }
Ejemplo n.º 2
0
        private async Task <Opportunity> UpdateDealTypeStatus(Opportunity opportunity, string requestId = "")
        {
            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();


            bool isLoanOfficerSelected = false;

            foreach (var item in opportunity.Content.TeamMembers)
            {
                //var groupID = group;
                var userId = item.Id;
                var oItem  = item;

                if (item.AssignedRole.DisplayName == "RelationshipManager")
                {
                    foreach (var process in opportunity.Content.DealType.ProcessList)
                    {
                        if (process.ProcessStep.ToLower() == "new opportunity")
                        {
                            process.Status = ActionStatus.InProgress;
                        }
                    }
                    try
                    {
                        Guard.Against.NullOrEmpty(item.Id, $"UpdateWorkflowAsync_{item.AssignedRole.DisplayName} Id NullOrEmpty", requestId);
                        var responseJson = await _graphUserAppService.AddGroupOwnerAsync(userId, groupID, requestId);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"RequestId: {requestId} - userId: {userId} - UpdateWorkflowAsync_AddGroupOwnerAsync_{item.AssignedRole.DisplayName} error in CreateWorkflowAsync: {ex}");
                    }
                }
                else if (item.AssignedRole.DisplayName == "LoanOfficer")
                {
                    if (!String.IsNullOrEmpty(item.Id))
                    {
                        isLoanOfficerSelected = true;
                    }

                    try
                    {
                        Guard.Against.NullOrEmpty(userId, "CreateWorkflowAsync_LoanOffier_Ups Null or empty", requestId);
                        var responseJson = await _graphUserAppService.AddGroupOwnerAsync(userId, groupID);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError($"RequestId: {requestId} - userId: {userId} - AddGroupOwnerAsync error in CreateWorkflowAsync: {ex}");
                    }
                }
                //else
                //{
                //adding of the team member
                //if (!String.IsNullOrEmpty(item.Fields.UserPrincipalName))
                //{
                try
                {
                    Guard.Against.NullOrEmpty(item.Id, $"UpdateStartProcessStatus_{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} - UpdateStartProcessStatus_AddGroupMemberAsync_{item.AssignedRole.DisplayName} error in CreateWorkflowAsync: {ex}");
                }
                //}
                //}
            }

            if (isLoanOfficerSelected)
            {
                foreach (var process in opportunity.Content.DealType.ProcessList)
                {
                    if (process.ProcessStep.ToLower() == "new opportunity" && process.Status != ActionStatus.Completed)
                    {
                        process.Status = ActionStatus.Completed;
                    }
                }
            }
            else
            {
                foreach (var process in opportunity.Content.DealType.ProcessList)
                {
                    if (process.ProcessStep.ToLower() == "new opportunity" && process.Status != ActionStatus.InProgress)
                    {
                        process.Status = ActionStatus.InProgress;
                    }
                }
            }

            return(opportunity);
        }