public async Task <StatusCodes> UpdateItemAsync(Industry entity, string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - IndustryRepo_UpdateItemAsync called.");

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

                // Create Json object for SharePoint create list item
                dynamic itemJson = new JObject();
                itemJson.Title = entity.Id;
                itemJson.Name  = entity.Name;

                var result = await _graphSharePointAppService.UpdateListItemAsync(siteList, entity.Id, itemJson.ToString(), requestId);

                _logger.LogInformation($"RequestId: {requestId} - IndustryRepo_UpdateItemAsync finished creating SharePoint list item.");

                return(StatusCodes.Status200OK);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - IndustryRepo_UpdateItemAsync error: {ex}");
                throw;
            }
        }
Example #2
0
        public async Task <StatusCodes> UpdateItemAsync(Notification notification, string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - UpdateItemAsync called.");
            Guard.Against.Null(notification, "UpdateItemAsync_notification null", requestId);
            Guard.Against.NullOrEmpty(notification.Id, "UpdateItemAsync_id null-empty", requestId);

            try
            {
                // Check result belongs to caller
                var currentUser = (_userContext.User.Claims).ToList().Find(x => x.Type == "preferred_username")?.Value;
                Guard.Against.NullOrEmpty(currentUser, "NotificationRepository_UpdateItemAsync CurrentUser null-empty", requestId);

                if (notification.Fields.SentTo != currentUser)
                {
                    _logger.LogError($"RequestId: {requestId} - NotificationRepository_UpdateItemAsync SentTo: {notification.Fields.SentTo} current user: {currentUser} AccessDeniedException");
                    throw new AccessDeniedException($"RequestId: {requestId} - NotificationRepository_UpdateItemAsync SentTo: {notification.Fields.SentTo} current user: {currentUser} AccessDeniedException");
                }

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

                // Create Json object for SharePoint update list item
                dynamic notificationJson = new JObject();
                notificationJson.IsRead = notification.Fields.IsRead;

                var response = await _graphSharePointAppService.UpdateListItemAsync(siteList, notification.Id, notificationJson.ToString(), requestId);

                _logger.LogInformation($"RequestId: {requestId} - UpdateItemAsync finished SharePoint List for notification.");

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