private async Task <Opportunity> UpdateStartProcessStatus(Opportunity opportunity, string requestId = "")
        {
            //get groupID
            //var opportunityName = WebUtility.UrlEncode(opportunity.DisplayName);
            //var options = new List<QueryParam>();
            //options.Add(new QueryParam("filter", $"startswith(displayName,'{opportunityName}')"));
            //var groupIdJson = await _graphUserAppService.GetGroupAsync(options, "", requestId);
            //dynamic jsonDyn = groupIdJson;

            //var groupID = String.Empty;
            //if (groupIdJson.HasValues)
            //{
            //    groupID = jsonDyn.value[0].id.ToString();
            //}


            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 the process steps that have been asigned at least member
            var teamMembersCheck = new List <string>();

            foreach (var item in opportunity.Content.TeamMembers)
            {
                //process steps check
                if (!String.IsNullOrEmpty(item.ProcessStep))
                {
                    var process = opportunity.Content.DealType.ProcessList.ToList().Find(x => x.ProcessStep.ToLower() == item.ProcessStep.ToLower());
                    if (process != null)
                    {
                        if (process.ProcessType.ToLower() == "checklisttab")
                        {
                            teamMembersCheck.Add(process.ProcessStep.ToLower());
                        }
                    }
                }

                //adding of the team member
                if (!item.AssignedRole.DisplayName.Equals("LoanOfficer", StringComparison.OrdinalIgnoreCase) &&
                    !item.AssignedRole.DisplayName.Equals("RelationshipManager", StringComparison.OrdinalIgnoreCase))
                {
                    //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}");
                    }
                    //}
                }
            }
            //check if all the processes in the deal type are assigned to at least one team member
            bool statusCheck = true;

            foreach (var process in opportunity.Content.DealType.ProcessList)
            {
                if (process.ProcessType.ToLower() == "checklisttab")
                {
                    if (!teamMembersCheck.Contains(process.ProcessStep.ToLower()))
                    {
                        statusCheck = false;
                    }
                }
            }
            //update the status of the start process step if all processes are assigned to a member
            if (statusCheck)
            {
                foreach (var process in opportunity.Content.DealType.ProcessList)
                {
                    if (process.ProcessStep.ToLower() == "start process")
                    {
                        if (process.Status != ActionStatus.Completed)
                        {
                            process.Status = ActionStatus.Completed;
                        }
                    }
                }
            }

            return(opportunity);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }