public async Task <ActionResult <IEnumerable <DraftNotificationSummary> > > GetAllDraftNotificationsAsync()
        {
            var notificationEntities = await this.notificationDataRepository.GetAllDraftNotificationsAsync();

            var result = new List <DraftNotificationSummary>();

            foreach (var notificationEntity in notificationEntities)
            {
                var summary = new DraftNotificationSummary
                {
                    Id    = notificationEntity.Id,
                    Title = notificationEntity.Title,
                };

                result.Add(summary);
            }

            return(result);
        }
示例#2
0
        public async Task <ActionResult <IEnumerable <DraftNotificationSummary> > > GetAllDraftNotificationsAsync()
        {
            try
            {
                var      authorizedCreatorUpns = this.configuration["AuthorizedCreatorUpns"];
                string[] superAdminsArray      = authorizedCreatorUpns.Split(",");
                var      superAdmins           = string.Join(",", superAdminsArray).ToLower();
                this.loggedinUser = this.HttpContext.User?.Identity?.Name;
                string channelIds = string.Empty;
                if (!superAdmins.Contains(this.loggedinUser.ToLower()))
                {
                    channelIds = await this.GetChannelIds();
                }

                var result = new List <DraftNotificationSummary>();
                var notificationEntities = await this.notificationDataRepository.GetAllDraftNotificationsAsync();

                foreach (var notificationEntity in notificationEntities)
                {
                    if (channelIds == string.Empty || channelIds.Contains(notificationEntity.Channel))
                    {
                        var summary = new DraftNotificationSummary
                        {
                            Id        = notificationEntity.Id,
                            Title     = notificationEntity.Title,
                            PublishOn = notificationEntity.PublishOn,
                        };

                        result.Add(summary);
                    }
                }
                return(result);
            }
            catch (Exception exception)
            {
                // Failed to fetch Draft Notification.
                this.logger.LogError(exception, $"Failed to get Draft notifications. Error message: {exception.Message}.");
                var result = new List <DraftNotificationSummary>();
                return(result);
            }
        }