Пример #1
0
        public async Task CreateNotificationsDeploymentDoneAsync(Guid linkId, string title, string message, IEnumerable <Guid> userIds, string url = default)
        {
            var existingNotifications = await notificationProvider.GetNotificationsFromLinkAsync(linkId).ConfigureAwait(false);

            // Save notif for all users
            foreach (var userId in userIds)
            {
                YNotification notification = null;

                notification = existingNotifications.FirstOrDefault(n => n.To == userId);

                if (notification == null)
                {
                    notification = new YNotification {
                        Id = Guid.NewGuid()
                    }
                }
                ;

                notification.LinkId   = linkId;
                notification.To       = userId;
                notification.IsRead   = false;
                notification.Title    = title;
                notification.Message  = message;
                notification.SendDate = DateTime.Now;
                notification.Url      = url;

                await notificationProvider.SaveNotificationAsync(notification);
            }

            // Broadcast to all user connected that are part of the deployment, to refresh notifications
            await SendRefreshNotificationsAsync(userIds);
        }
        public async Task <YNotification> SaveNotificationAsync(YNotification notification)
        {
            try
            {
                using CosmosClient client = new CosmosClient(accountEndpoint, accountKey, clientOptions);
                var container = client.GetContainer(databaseName, containerName);

                ItemResponse <YNotification> response = await container.UpsertItemAsync(
                    notification, engineRequestPartitionKey).ConfigureAwait(false);

                return(notification);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                throw;
            }
        }
Пример #3
0
        public async Task <ActionResult <YNotification> > SaveNotificationAsync(Guid id, [FromBody] YNotification notification)
        {
            HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi);

            var userObjectId = this.User.GetObjectId();

            if (id != notification.Id)
            {
                return(new UnprocessableEntityObjectResult("id and entity differs"));
            }

            if (string.IsNullOrEmpty(userObjectId))
            {
                return(new UnauthorizedObjectResult("User unknown"));
            }

            var savedNotif = await this.notificationProvider.SaveNotificationAsync(notification).ConfigureAwait(false);

            return(savedNotif);
        }