Esempio n. 1
0
        protected void AddNotification(
            LastComponentNotification lastComponentNotification,
            StatusInfo statusInfo,
            Subscription subscription,
            AccountDbContext accountDbContext,
            NotificationReason reason)
        {
            var realEvent = accountDbContext.Events.Find(statusInfo.EventId);

            if (realEvent == null)
            {
                return;
            }

            Interlocked.Increment(ref CreatedNotificationsCount);

            var newNotification = new Notification()
            {
                Id             = Guid.NewGuid(),
                Address        = lastComponentNotification.Address,
                CreationDate   = Now(),
                EventId        = statusInfo.EventId,
                Status         = NotificationStatus.InQueue,
                SubscriptionId = subscription.Id,
                Type           = lastComponentNotification.Type,
                UserId         = subscription.UserId,
                Reason         = reason
            };

            if (newNotification.Type == NotificationType.Http)
            {
                newNotification.NotificationHttp = new NotificationHttp()
                {
                    Notification = newNotification
                                   //Json = GetNotificationJson(lastComponentNotification.Component, eventObj)
                };
            }

            var notificationRepository = accountDbContext.GetNotificationRepository();

            notificationRepository.Add(newNotification);

            lastComponentNotification.Update(newNotification, statusInfo.Importance);

            accountDbContext.SaveChanges();
        }