Esempio n. 1
0
        public Core.Notification.Notification GetNewNotification(string type, string objectId, string objectTypeId, string language)
        {
            var notifications = GetNotifications();
            var retVal        = notifications.FirstOrDefault(x => x.GetType().Name == type);

            if (retVal != null)
            {
                retVal.ObjectId     = objectId;
                retVal.ObjectTypeId = objectTypeId;
                retVal.Language     = language;
                if (retVal != null)
                {
                    var template = _notificationTemplateService.GetByNotification(type, objectId, objectTypeId, language);
                    if (template != null)
                    {
                        retVal.NotificationTemplate = template;
                    }
                    else if (retVal.NotificationTemplate == null)
                    {
                        retVal.NotificationTemplate = new NotificationTemplate();
                    }
                }

                if (retVal.NotificationTemplate != null && string.IsNullOrEmpty(retVal.NotificationTemplate.NotificationTypeId))
                {
                    retVal.NotificationTemplate.NotificationTypeId = type;
                }
            }

            return(retVal);
        }
Esempio n. 2
0
        public Core.Notifications.Notification GetNewNotification(string type, string objectId, string objectTypeId, string language)
        {
            var notifications = GetNotifications();
            var retVal        = notifications.FirstOrDefault(x => x.GetType().Name == type);

            if (retVal == null)
            {
                throw new NullReferenceException("Notification  " + type + " not found. Please register this type by notificationManager.RegisterNotificationType before use");
            }

            retVal.ObjectId     = objectId;
            retVal.ObjectTypeId = objectTypeId;
            retVal.Language     = language;
            if (retVal != null)
            {
                var template = _notificationTemplateService.GetByNotification(type, objectId, objectTypeId, language);
                if (template != null)
                {
                    retVal.NotificationTemplate = template;
                }
                else if (retVal.NotificationTemplate == null)
                {
                    retVal.NotificationTemplate = new NotificationTemplate();
                }
            }

            if (retVal.NotificationTemplate != null && string.IsNullOrEmpty(retVal.NotificationTemplate.NotificationTypeId))
            {
                retVal.NotificationTemplate.NotificationTypeId = type;
            }

            return(retVal);
        }
 private void SetNotificationTemplate(Core.Notification.Notification notification)
 {
     if (notification != null)
     {
         var template = _notificationTemplateService.GetByNotification(notification.Type, notification.ObjectId);
         if (template != null)
         {
             notification.NotificationTemplate = template;
         }
     }
 }
Esempio n. 4
0
        public IHttpActionResult GetNotificationTemplate(string type, string objectId)
        {
            var retVal = _notificationTemplateService.GetByNotification(type, objectId);

            if (retVal == null)
            {
                var notification = _notificationManager.GetNewNotification(type);
                if (notification != null)
                {
                    retVal = notification.NotificationTemplate;
                }
            }

            return(Ok(retVal.ToWebModel()));
        }
        public Notification GetNewNotification(string type, string objectId, string objectTypeId, string language)
        {
            var notifications = GetNotifications();
            var retVal        = notifications.FirstOrDefault(x => x.GetType().Name == type);

            if (retVal == null)
            {
                //try to find in derived types
                retVal = notifications.FirstOrDefault(x => x.GetType().GetTypeInheritanceChain().Select(y => y.Name).Contains(type));
            }
            if (retVal == null)
            {
                throw new InvalidOperationException($"Notification {type} not found. Please register this type by notificationManager.RegisterNotificationType before use");
            }

            retVal.ObjectId     = objectId;
            retVal.ObjectTypeId = objectTypeId;
            retVal.Language     = language;

            var notificationTypeName = retVal.GetType().Name;
            var template             = _notificationTemplateService.GetByNotification(notificationTypeName, objectId, objectTypeId, language);

            if (template != null)
            {
                retVal.NotificationTemplate = template;
            }
            else if (retVal.NotificationTemplate == null)
            {
                retVal.NotificationTemplate = new NotificationTemplate();
            }

            if (retVal.NotificationTemplate != null && string.IsNullOrEmpty(retVal.NotificationTemplate.NotificationTypeId))
            {
                retVal.NotificationTemplate.NotificationTypeId = type;
            }

            return(retVal);
        }