Exemplo n.º 1
0
        public async Task <IList <Dashboard> > GetAllAsync(string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - DashboardRepository_GetAllAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.DashboardListId
                };

                var json = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                var    itemsList = new List <Dashboard>();
                JArray jsonArray = JArray.Parse(json["value"].ToString());

                foreach (var item in jsonArray)
                {
                    itemsList.Add(JsonConvert.DeserializeObject <Dashboard>(item["fields"].ToString(), new JsonSerializerSettings
                    {
                        MissingMemberHandling = MissingMemberHandling.Ignore
                    }));
                }

                return(itemsList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - DashboardRepository_GetAllAsync error: {ex}");
                throw;
            }
        }
        private async Task <IList <Permission> > GetPermissionListAsync(string requestId)
        {
            _logger.LogInformation($"RequestId: {requestId} - PermissionRepo_GetPermissionListAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.Permissions
                };

                dynamic json = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                var itemsList = new List <Permission>();
                foreach (var item in json.value)
                {
                    itemsList.Add(JsonConvert.DeserializeObject <Permission>(item["fields"].ToString(), new JsonSerializerSettings
                    {
                        MissingMemberHandling = MissingMemberHandling.Ignore
                    }));
                }

                return(itemsList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - PermissionRepo_GetPermissionListAsync error: {ex}");
                throw;
            }
        }
        // Private methods
        private async Task <JArray> GetRoleMappingListAsync(string requestId = "")
        {
            try
            {
                if (_roleMappingList == null)
                {
                    var siteList = new SiteList
                    {
                        SiteId = _appOptions.ProposalManagementRootSiteId,
                        ListId = _appOptions.RolesListId
                    };

                    var json = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                    JArray jArrayResult = JArray.Parse(json["value"].ToString());

                    _roleMappingList = jArrayResult;
                }

                return(_roleMappingList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - GetRoleMappingList Service Exception: {ex}");
                throw new ResponseException($"RequestId: {requestId} - GetRoleMappingList Service Exception: {ex}");
            }
        }
Exemplo n.º 4
0
        private async Task <IList <Role> > GetRoleListAsync(string requestId)
        {
            _logger.LogInformation($"RequestId: {requestId} - RolesRepo_GetRoleListAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.RoleListId
                };

                var json = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                JArray jsonArray = JArray.Parse(json["value"].ToString());

                var itemsList = new List <Role>();
                foreach (var item in jsonArray)
                {
                    var role = Role.Empty;
                    role.Id          = item["fields"]["id"].ToString() ?? String.Empty;
                    role.DisplayName = item["fields"]["Name"].ToString() ?? String.Empty;

                    itemsList.Add(role);
                }

                return(itemsList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - RolesRepo_GetRoleListAsync error: {ex}");
                throw;
            }
        }
Exemplo n.º 5
0
        public async Task <IList <Template> > GetAllAsync(string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - TemplateRepository_GetAllAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.TemplateListId
                };

                var json = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                dynamic jsonDyn   = json;
                var     itemsList = new List <Template>();
                if (jsonDyn.value.HasValues)
                {
                    foreach (var item in jsonDyn.value)
                    {
                        var template = Template.Empty;
                        template.Id = item.fields.id.ToString();
                        var x = item.fields;
                        template.TemplateName = item.fields.TemplateName.ToString();
                        template.Description  = item.fields.Description.ToString();
                        template.LastUsed     = Convert.ToDateTime(item.fields.LastUsed.ToString());
                        //get the user profile object
                        var createdBy = JsonConvert.DeserializeObject <UserProfile>(item.fields.CreatedBy.ToString(), new JsonSerializerSettings
                        {
                            MissingMemberHandling = MissingMemberHandling.Ignore,
                            NullValueHandling     = NullValueHandling.Ignore
                        });
                        template.CreatedBy = createdBy;
                        //get processList
                        var processList = JsonConvert.DeserializeObject <IList <Process> >(item.fields.ProcessList.ToString(), new JsonSerializerSettings
                        {
                            MissingMemberHandling = MissingMemberHandling.Ignore,
                            NullValueHandling     = NullValueHandling.Ignore
                        });
                        template.ProcessList = processList;

                        itemsList.Add(template);
                    }
                }

                return(itemsList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - TemplateRepo_GetAllAsync error: {ex}");
                throw;
            }
        }
Exemplo n.º 6
0
        public async Task <IList <Template> > GetAllAsync(string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - TemplateRepository_GetAllAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.TemplateListId
                };

                dynamic jsonDyn = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                var itemsList = new List <Template>();

                if (jsonDyn.value.HasValues)
                {
                    foreach (var item in jsonDyn.value)
                    {
                        var obj = JObject.Parse(item.ToString()).SelectToken("fields");
                        itemsList.Add(new Template
                        {
                            Id              = obj.SelectToken("id")?.ToString(),
                            TemplateName    = obj.SelectToken("TemplateName")?.ToString(),
                            Description     = obj.SelectToken("Description")?.ToString(),
                            LastUsed        = Convert.ToDateTime(obj.SelectToken("LastUsed")?.ToString()),
                            DefaultTemplate = obj.SelectToken("DefaultTemplate") != null ? obj.SelectToken("DefaultTemplate").ToString() == "True" : false,
                            CreatedBy       = obj.SelectToken("CreatedBy") != null ? JsonConvert.DeserializeObject <UserProfile>(obj.SelectToken("CreatedBy").ToString(), new JsonSerializerSettings
                            {
                                MissingMemberHandling = MissingMemberHandling.Ignore,
                                NullValueHandling     = NullValueHandling.Ignore
                            }) : UserProfile.Empty,
                            ProcessList = obj.SelectToken("ProcessList") != null ? JsonConvert.DeserializeObject <IList <Process> >(obj.SelectToken("ProcessList").ToString(), new JsonSerializerSettings
                            {
                                MissingMemberHandling = MissingMemberHandling.Ignore,
                                NullValueHandling     = NullValueHandling.Ignore
                            }) : new List <Process>()
                        });
                    }
                }

                return(itemsList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - TemplateRepo_GetAllAsync error: {ex}");
                throw;
            }
        }
Exemplo n.º 7
0
        private async Task <IList <Role> > GetRoleListAsync(string requestId)
        {
            _logger.LogInformation($"RequestId: {requestId} - RolesRepo_GetRoleListAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.RoleListId
                };

                dynamic json = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                var itemsList = new List <Role>();
                if (json.value.HasValues)
                {
                    foreach (var item in json.value)
                    {
                        var obj = JObject.Parse(item.ToString()).SelectToken("fields");
                        itemsList.Add(new Role
                        {
                            Id              = obj.SelectToken("id")?.ToString(),
                            AdGroupName     = obj.SelectToken("AdGroupName")?.ToString(),
                            DisplayName     = obj.SelectToken("Role")?.ToString(),
                            TeamsMembership = obj.SelectToken("TeamsMembership") != null? TeamsMembership.FromName(obj.SelectToken("TeamsMembership").ToString()): TeamsMembership.None,
                            Permissions     = obj.SelectToken("Permissions") != null ? JsonConvert.DeserializeObject <IList <Permission> >(obj.SelectToken("Permissions").ToString(), new JsonSerializerSettings
                            {
                                MissingMemberHandling = MissingMemberHandling.Ignore,
                                NullValueHandling     = NullValueHandling.Ignore
                            }) : new List <Permission>()
                        });
                    }
                }


                return(itemsList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - RolesRepo_GetRoleListAsync error: {ex}");
                throw;
            }
        }
Exemplo n.º 8
0
        private async Task <IList <RoleMapping> > GetRoleMappingListAsync(string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - RoleMappingRepo_GetRoleMappingListAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.RoleMappingsListId
                };

                var json = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                JArray jsonArray = JArray.Parse(json["value"].ToString());
                var    itemsList = new List <RoleMapping>();
                foreach (var item in jsonArray)
                {
                    var rolemapping = RoleMapping.Empty;
                    rolemapping.Id = item["fields"]["id"].ToString() ?? String.Empty;
                    //Bug Fix
                    if (item["fields"]["ADGroupName"] != null)
                    {
                        rolemapping.AdGroupName      = item["fields"]["ADGroupName"].ToString();
                        rolemapping.Role.DisplayName = item["fields"]["Role"].ToString();
                        JArray jsonAr = JArray.Parse(item["fields"]["Permissions"].ToString());
                        foreach (var p in jsonAr)
                        {
                            rolemapping.Permissions.Add(JsonConvert.DeserializeObject <Permission>(p.ToString()));
                        }
                        itemsList.Add(rolemapping);
                    }
                }

                return(itemsList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - RoleMappingRepo_GetRoleMappingListAsync error: {ex}");
                throw;
            }
        }
Exemplo n.º 9
0
        public async Task <IList <ProcessesType> > GetAllAsync(string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - ProcessRepository_GetAllAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.ProcessListId
                };

                dynamic json = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                var itemsList = new List <ProcessesType>();
                if (json.value.HasValues)
                {
                    foreach (var item in json.value)
                    {
                        var obj = JObject.Parse(item.ToString()).SelectToken("fields");
                        itemsList.Add(new ProcessesType
                        {
                            Id          = obj.SelectToken("id")?.ToString(),
                            ProcessType = obj.SelectToken("ProcessType")?.ToString(),
                            ProcessStep = obj.SelectToken("ProcessStep")?.ToString(),
                            Channel     = obj.SelectToken("Channel")?.ToString(),
                            RoleId      = obj.SelectToken("RoleId") != null? obj.SelectToken("RoleId").ToString() : String.Empty,
                            RoleName    = obj.SelectToken("RoleName") != null ? obj.SelectToken("RoleName").ToString() : String.Empty
                        });
                    }
                }

                return(itemsList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - ProcessRepo_GetAllAsync error: {ex}");
                throw;
            }
        }
Exemplo n.º 10
0
        public async Task <IList <ProcessesType> > GetAllAsync(string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - ProcessRepository_GetAllAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.ProcessListId
                };

                var json = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                dynamic jsonDyn   = json;
                var     itemsList = new List <ProcessesType>();
                if (jsonDyn.value.HasValues)
                {
                    foreach (var item in jsonDyn.value)
                    {
                        var process = ProcessesType.Empty;
                        process.Id = item.fields.id.ToString();
                        var x = item.fields;
                        process.ProcessType = item.fields.ProcessType.ToString();
                        process.ProcessStep = item.fields.ProcessStep.ToString();
                        process.Channel     = item.fields.Channel.ToString();

                        itemsList.Add(process);
                    }
                }

                return(itemsList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - ProcessRepo_GetAllAsync error: {ex}");
                throw;
            }
        }
Exemplo n.º 11
0
        private async Task <IList <Groups> > GetGroupsListAsync(string requestId)
        {
            _logger.LogInformation($"RequestId: {requestId} - GroupsRepo_GetGroupsListAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.GroupsListId
                };

                dynamic json = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                var itemsList = new List <Groups>();
                foreach (var item in json.value)
                {
                    var obj = JObject.Parse(item.ToString()).SelectToken("fields");
                    itemsList.Add(new Groups
                    {
                        Id        = obj.SelectToken("id")?.ToString(),
                        GroupName = obj.SelectToken("GroupName")?.ToString(),
                        Processes = obj.SelectToken("Process") != null ? JsonConvert.DeserializeObject <IList <ProcessesType> >(obj.SelectToken("Process").ToString(), new JsonSerializerSettings
                        {
                            MissingMemberHandling = MissingMemberHandling.Ignore,
                            NullValueHandling     = NullValueHandling.Ignore
                        }) : new List <ProcessesType>()
                    });
                }

                return(itemsList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - GroupsRepo_GetGroupsListAsync error: {ex}");
                throw;
            }
        }
Exemplo n.º 12
0
        public async Task <IList <Opportunity> > GetAllAsync(string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - OpportunityRepository_GetAllAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.OpportunitiesListId
                };

                //Granular Access : Start
                var access = await CheckAccessAsync(PermissionNeededTo.ReadPartial, PermissionNeededTo.Read, PermissionNeededTo.ReadAll, requestId);

                var currentUser = (_userContext.User.Claims).ToList().Find(x => x.Type == "preferred_username")?.Value;
                //Granular Access : End
                var currentUserScope = (_userContext.User.Claims).ToList().Find(x => x.Type == "http://schemas.microsoft.com/identity/claims/scope")?.Value;
                Guard.Against.NullOrEmpty(currentUser, "OpportunityRepository_GetAllAsync CurrentUser null-empty", requestId);

                var callerUser = await _userProfileRepository.GetItemByUpnAsync(currentUser, requestId);

                Guard.Against.Null(callerUser, "_userProfileRepository.GetItemByUpnAsync Null", requestId);
                if (currentUser != callerUser.Fields.UserPrincipalName)
                {
                    _logger.LogError($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                    throw new AccessDeniedException($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                }

                var isLoanOfficer         = false;
                var isRelationshipManager = false;
                var isAdmin = false;

                if (callerUser.Fields.UserRoles.Find(x => x.DisplayName == "LoanOfficer") != null)
                {
                    isLoanOfficer = true;
                }
                if (callerUser.Fields.UserRoles.Find(x => x.DisplayName == "RelationshipManager") != null)
                {
                    isRelationshipManager = true;
                }
                if (callerUser.Fields.UserRoles.Find(x => x.DisplayName == "Administrator") != null)
                {
                    //Granular Access : Start
                    //Admin access
                    if (StatusCodes.Status200OK == await _authorizationService.CheckAccessFactoryAsync(PermissionNeededTo.Admin, requestId))
                    {
                        isAdmin = true;
                    }
                    //Granular Access : End
                }
                if (currentUserScope != "access_as_user") //TODO: Temp conde while graular access control is finished in w3
                {
                    isAdmin = true;
                }

                //Granular Access : Start
                if (access.haveAccess == false && access.haveSuperAcess == false && access.havePartial == false)
                {
                    // This user is not having any read permissions, so he won't be able to list of opportunities
                    _logger.LogError($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                    throw new AccessDeniedException($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                }
                //Granular Access : End

                var options                 = new List <QueryParam>();
                var jsonLoanOfficer         = new JObject();
                var jsonRelationshipManager = new JObject();
                var jsonAdmin               = new JObject();
                var itemsList               = new List <Opportunity>();
                var jsonArray               = new JArray();

                if (isAdmin)
                {
                    jsonAdmin = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                    if (jsonAdmin.HasValues)
                    {
                        jsonArray = JArray.Parse(jsonAdmin["value"].ToString());
                    }


                    foreach (var item in jsonArray)
                    {
                        var opportunityJson = item["fields"]["OpportunityObject"].ToString();

                        var oppArtifact = JsonConvert.DeserializeObject <Opportunity>(opportunityJson.ToString(), new JsonSerializerSettings
                        {
                            MissingMemberHandling = MissingMemberHandling.Ignore,
                            NullValueHandling     = NullValueHandling.Ignore
                        });

                        oppArtifact.Id = item["fields"]["id"].ToString();

                        itemsList.Add(oppArtifact);
                    }
                }
                else
                {
                    if (isLoanOfficer)
                    {
                        options.Add(new QueryParam("filter", $"startswith(fields/LoanOfficer,'{callerUser.Id}')"));
                        jsonLoanOfficer = await _graphSharePointAppService.GetListItemsAsync(siteList, options, "all", requestId);
                    }


                    if (isRelationshipManager)
                    {
                        options.Add(new QueryParam("filter", $"startswith(fields/RelationshipManager,'{callerUser.Id}')"));
                        jsonRelationshipManager = await _graphSharePointAppService.GetListItemsAsync(siteList, options, "all", requestId);
                    }

                    if (jsonLoanOfficer.HasValues)
                    {
                        jsonArray = JArray.Parse(jsonLoanOfficer["value"].ToString());
                    }


                    foreach (var item in jsonArray)
                    {
                        var opportunityJson = item["fields"]["OpportunityObject"].ToString();

                        var oppArtifact = JsonConvert.DeserializeObject <Opportunity>(opportunityJson.ToString(), new JsonSerializerSettings
                        {
                            MissingMemberHandling = MissingMemberHandling.Ignore,
                            NullValueHandling     = NullValueHandling.Ignore
                        });

                        oppArtifact.Id = item["fields"]["id"].ToString();

                        //Granular Access : Start
                        if (access.haveSuperAcess)
                        {
                            itemsList.Add(oppArtifact);
                        }
                        else
                        {
                            if ((oppArtifact.Content.TeamMembers).ToList().Any
                                    (teamMember => teamMember.Fields.UserPrincipalName == currentUser))
                            {
                                itemsList.Add(oppArtifact);
                            }
                        }
                        //Granular Access : end
                    }

                    if (jsonRelationshipManager.HasValues)
                    {
                        jsonArray = JArray.Parse(jsonRelationshipManager["value"].ToString());
                    }

                    foreach (var item in jsonArray)
                    {
                        var opportunityJson = item["fields"]["OpportunityObject"].ToString();

                        var oppArtifact = JsonConvert.DeserializeObject <Opportunity>(opportunityJson.ToString(), new JsonSerializerSettings
                        {
                            MissingMemberHandling = MissingMemberHandling.Ignore,
                            NullValueHandling     = NullValueHandling.Ignore
                        });

                        oppArtifact.Id = item["fields"]["id"].ToString();

                        var dupeOpp = itemsList.Find(x => x.DisplayName == oppArtifact.DisplayName);
                        if (dupeOpp == null)
                        {
                            //Granular Access : Start
                            if (access.haveSuperAcess)
                            {
                                itemsList.Add(oppArtifact);
                            }
                            else
                            {
                                if ((oppArtifact.Content.TeamMembers).ToList().Any
                                        (teamMember => teamMember.Fields.UserPrincipalName == currentUser))
                                {
                                    itemsList.Add(oppArtifact);
                                }
                            }
                            //Granular Access : end
                        }
                    }
                }

                return(itemsList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - OpportunityRepository_GetAllAsync Service Exception: {ex}");
                throw new ResponseException($"RequestId: {requestId} - OpportunityRepository_GetAllAsync Service Exception: {ex}");
            }
        }
        public async Task <IList <MetaData> > GetAllAsync(string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - MetaDataRepo_GetAllAsync called.");

            try
            {
                //check access
                //await _authorizationService.Value.CheckAdminAccsessAsync(requestId);
                var metaDataList = new List <MetaData>();
                var json         = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                var jsonArray = json["value"] as JArray;

                if (jsonArray == null)
                {
                    return(metaDataList);
                }

                foreach (var item in jsonArray)
                {
                    var metaData = MetaData.Empty;
                    metaData.Id = item.SelectToken("fields.id")?.ToObject <string>();
                    if (!String.IsNullOrEmpty(metaData.Id))
                    {
                        metaData.FieldType   = FieldType.FromName(item["fields"]["FieldType"].ToString());
                        metaData.DisplayName = item.SelectToken("fields.FieldName")?.ToObject <string>();
                        metaData.Screen      = item.SelectToken("fields.FieldScreen")?.ToObject <string>();

                        try
                        {
                            if (metaData.FieldType == FieldType.DropDown)
                            {
                                JArray jsonAr = JArray.Parse(item["fields"]["FieldValue"].ToString());

                                metaData.Values = new List <DropDownMetaDataValue>();
                                foreach (var property in jsonAr)
                                {
                                    metaData.Values.Add(property.ToObject <DropDownMetaDataValue>());
                                }
                            }
                            else
                            {
                                metaData.Values = item["fields"]["FieldValue"].ToString() ?? String.Empty;
                            }
                        }
                        catch
                        {
                            metaData.Values = String.Empty;
                        }
                    }
                    metaDataList.Add(metaData);
                }

                return(metaDataList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - MetaDataRepo_GetAllAsync error: {ex}");
                throw;
            }
        }
        public async Task <IList <Opportunity> > GetAllAsync(string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - OpportunityRepository_GetAllAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.OpportunitiesListId
                };

                var currentUser = (_userContext.User.Claims).ToList().Find(x => x.Type == "preferred_username")?.Value;
                Guard.Against.NullOrEmpty(currentUser, "OpportunityRepository_GetAllAsync CurrentUser null-empty", requestId);

                var callerUser = await _userProfileRepository.GetItemByUpnAsync(currentUser, requestId);

                Guard.Against.Null(callerUser, "_userProfileRepository.GetItemByUpnAsync Null", requestId);
                if (currentUser != callerUser.Fields.UserPrincipalName)
                {
                    _logger.LogError($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                    throw new AccessDeniedException($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                }

                var isLoanOfficer         = false;
                var isRelationshipManager = false;
                var isAdmin = false;

                if (callerUser.Fields.UserRoles.Find(x => x.DisplayName == "LoanOfficer") != null)
                {
                    isLoanOfficer = true;
                }
                if (callerUser.Fields.UserRoles.Find(x => x.DisplayName == "RelationshipManager") != null)
                {
                    isRelationshipManager = true;
                }
                if (callerUser.Fields.UserRoles.Find(x => x.DisplayName == "Administrator") != null)
                {
                    isAdmin = true;
                }

                if (isLoanOfficer == false && isRelationshipManager == false && isAdmin == false)
                {
                    // This user is not LoannOfficer or RelationshipManager so it does not has access to list opportunities
                    _logger.LogError($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                    throw new AccessDeniedException($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                }

                var options                 = new List <QueryParam>();
                var jsonLoanOfficer         = new JObject();
                var jsonRelationshipManager = new JObject();
                var jsonAdmin               = new JObject();
                var itemsList               = new List <Opportunity>();
                var jsonArray               = new JArray();

                if (isAdmin)
                {
                    jsonAdmin = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                    if (jsonAdmin.HasValues)
                    {
                        jsonArray = JArray.Parse(jsonAdmin["value"].ToString());
                    }


                    foreach (var item in jsonArray)
                    {
                        var opportunityJson = item["fields"]["OpportunityObject"].ToString();

                        var oppArtifact = JsonConvert.DeserializeObject <Opportunity>(opportunityJson.ToString(), new JsonSerializerSettings
                        {
                            MissingMemberHandling = MissingMemberHandling.Ignore,
                            NullValueHandling     = NullValueHandling.Ignore
                        });

                        oppArtifact.Id = item["fields"]["id"].ToString();

                        itemsList.Add(oppArtifact);
                    }
                }
                else
                {
                    if (isLoanOfficer)
                    {
                        options.Add(new QueryParam("filter", $"startswith(fields/LoanOfficer,'{callerUser.Id}')"));
                        jsonLoanOfficer = await _graphSharePointAppService.GetListItemsAsync(siteList, options, "all", requestId);
                    }


                    if (isRelationshipManager)
                    {
                        options.Add(new QueryParam("filter", $"startswith(fields/RelationshipManager,'{callerUser.Id}')"));
                        jsonRelationshipManager = await _graphSharePointAppService.GetListItemsAsync(siteList, options, "all", requestId);
                    }

                    if (jsonLoanOfficer.HasValues)
                    {
                        jsonArray = JArray.Parse(jsonLoanOfficer["value"].ToString());
                    }


                    foreach (var item in jsonArray)
                    {
                        var opportunityJson = item["fields"]["OpportunityObject"].ToString();

                        var oppArtifact = JsonConvert.DeserializeObject <Opportunity>(opportunityJson.ToString(), new JsonSerializerSettings
                        {
                            MissingMemberHandling = MissingMemberHandling.Ignore,
                            NullValueHandling     = NullValueHandling.Ignore
                        });

                        oppArtifact.Id = item["fields"]["id"].ToString();

                        itemsList.Add(oppArtifact);
                    }

                    if (jsonRelationshipManager.HasValues)
                    {
                        jsonArray = JArray.Parse(jsonRelationshipManager["value"].ToString());
                    }

                    foreach (var item in jsonArray)
                    {
                        var opportunityJson = item["fields"]["OpportunityObject"].ToString();

                        var oppArtifact = JsonConvert.DeserializeObject <Opportunity>(opportunityJson.ToString(), new JsonSerializerSettings
                        {
                            MissingMemberHandling = MissingMemberHandling.Ignore,
                            NullValueHandling     = NullValueHandling.Ignore
                        });

                        oppArtifact.Id = item["fields"]["id"].ToString();

                        var dupeOpp = itemsList.Find(x => x.DisplayName == oppArtifact.DisplayName);
                        if (dupeOpp == null)
                        {
                            itemsList.Add(oppArtifact);
                        }
                    }
                }

                return(itemsList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - OpportunityRepository_GetAllAsync Service Exception: {ex}");
                throw new ResponseException($"RequestId: {requestId} - OpportunityRepository_GetAllAsync Service Exception: {ex}");
            }
        }
        public async Task <IList <Opportunity> > GetAllAsync(string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - OpportunityRepository_GetAllAsync called.");

            try
            {
                var siteList = new SiteList
                {
                    SiteId = _appOptions.ProposalManagementRootSiteId,
                    ListId = _appOptions.OpportunitiesListId
                };

                //Granular Access : Start
                var access = await CheckAccessAsync(PermissionNeededTo.ReadPartial, PermissionNeededTo.Read, PermissionNeededTo.ReadAll, requestId);

                var currentUser = (_userContext.User.Claims).ToList().Find(x => x.Type == "preferred_username")?.Value;
                //Granular Access : End
                var currentUserScope = (_userContext.User.Claims).ToList().Find(x => x.Type == "http://schemas.microsoft.com/identity/claims/scope")?.Value;
                Guard.Against.NullOrEmpty(currentUser, "OpportunityRepository_GetAllAsync CurrentUser null-empty", requestId);

                var callerUser = await _userProfileRepository.GetItemByUpnAsync(currentUser, requestId);

                Guard.Against.Null(callerUser, "_userProfileRepository.GetItemByUpnAsync Null", requestId);
                if (currentUser != callerUser.Fields.UserPrincipalName)
                {
                    _logger.LogError($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                    throw new AccessDeniedException($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                }

                //Granular Access : Start
                if (access.haveAccess == false && access.haveSuperAcess == false && access.havePartial == false)
                {
                    // This user is not having any read permissions, so he won't be able to list of opportunities
                    _logger.LogError($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                    throw new AccessDeniedException($"RequestId: {requestId} - OpportunityRepository_GetItemByIdAsync current user: {currentUser} AccessDeniedException");
                }
                //Granular Access : End

                var isMember = false;
                var isOwner  = false;


                if (callerUser.Fields.UserRoles.Find(x => x.TeamsMembership == TeamsMembership.Owner) != null)
                {
                    isOwner = true;
                }
                else if (callerUser.Fields.UserRoles.Find(x => x.TeamsMembership == TeamsMembership.Member) != null)
                {
                    isMember = true;
                }


                var itemsList = new List <Opportunity>();

                if (isOwner || isMember)
                {
                    dynamic json = await _graphSharePointAppService.GetListItemsAsync(siteList, "all", requestId);

                    if (json.value.HasValues)
                    {
                        foreach (var item in (JArray)json["value"])
                        {
                            var obj = JObject.Parse(item.ToString()).SelectToken("fields");

                            var oppArtifact = JsonConvert.DeserializeObject <Opportunity>(obj.SelectToken("OpportunityObject").ToString(), new JsonSerializerSettings
                            {
                                MissingMemberHandling = MissingMemberHandling.Ignore,
                                NullValueHandling     = NullValueHandling.Ignore
                            });

                            oppArtifact.Id             = obj.SelectToken("id")?.ToString();
                            oppArtifact.TemplateLoaded = obj.SelectToken("TemplateLoaded") != null?obj.SelectToken("TemplateLoaded").ToString() == "True" : false;


                            //Granular Access : Start
                            if (access.haveSuperAcess || isOwner)
                            {
                                itemsList.Add(oppArtifact);
                            }
                            else
                            {
                                if ((oppArtifact.Content.TeamMembers).ToList().Any
                                        (teamMember => teamMember.Fields.UserPrincipalName == currentUser))
                                {
                                    itemsList.Add(oppArtifact);
                                }
                            }
                            //Granular Access : end
                        }
                    }
                }

                return(itemsList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - OpportunityRepository_GetAllAsync Service Exception: {ex}");
                throw new ResponseException($"RequestId: {requestId} - OpportunityRepository_GetAllAsync Service Exception: {ex}");
            }
        }