public async Task <IList <Industry> > GetAllAsync(string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - IndustryRepo_GetAllAsync called.");

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

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

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

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

                return(itemsList);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - IndustryRepo_GetAllAsync error: {ex}");
                throw;
            }
        }
Ejemplo n.º 2
0
        public async Task <IList <Notification> > GetAllAsync(string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - GetAllAsync called.");

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

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

                var options = new List <QueryParam>();
                options.Add(new QueryParam("filter", $"startswith(fields/SentTo,'{currentUser}')"));

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

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

                var itemsList = new List <Notification>();
                foreach (var item in jsonArray)
                {
                    itemsList.Add(await MapToEntityAsync(item));
                }
                var sorteditemsList = itemsList.OrderByDescending(x => x.Fields.SentDate).ToList();

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