private void Events_UserAfterCreate(UserAfterCreateEventArgs args)
        {
            List <SystemNotificationPreference> defaults = DefaultSystemNotifications.GetSystemNotificationPreferences();

            if (defaults != null && defaults.Count > 0)
            {
                ApiList <NotificationDistributionTypeInfo> distributionTypes = PublicApi.Notifications.ListDistributionTypes();
                ApiList <NotificationTypeInfo>             notificationTypes = PublicApi.Notifications.ListNotificationTypes();
                foreach (NotificationTypeInfo notificationType in notificationTypes)
                {
                    foreach (NotificationDistributionTypeInfo distributionType in distributionTypes)
                    {
                        SystemNotificationPreference preference = (
                            from p in defaults
                            where p.NotificationTypeId == notificationType.NotificationTypeId && p.DistributionTypeId == distributionType.DistributionTypeId
                            select p).FirstOrDefault();
                        if (preference != null)
                        {
                            PublicApi.Users.RunAsUser(args.Id.Value, () => PublicApi.Notifications.UpdatePreference(preference.NotificationTypeId, preference.DistributionTypeId, preference.IsEnabled));
                        }
                        else
                        {
                            PublicApi.Users.RunAsUser(args.Id.Value, () => PublicApi.Notifications.UpdatePreference(notificationType.NotificationTypeId, distributionType.DistributionTypeId, false));
                        }
                    }
                }
            }
        }
Beispiel #2
0
 public void UpdateUserDefaultNotifications(String notificationType, String distributionType, bool enable)
 {
     if (PublicApi.RoleUsers.IsUserInRoles(PublicApi.Users.AccessingUser.Username, new string[] { "Administrators" }))
     {
         Guid  notificationTypeId = Guid.Parse(notificationType);
         Guid  distributionTypeId = Guid.Parse(distributionType);
         Group rootGroup          = PublicApi.Groups.Root;
         List <SystemNotificationPreference> defaults   = DefaultSystemNotifications.GetSystemNotificationPreferences();
         SystemNotificationPreference        preference = (from p in defaults where p.NotificationTypeId == notificationTypeId && p.DistributionTypeId == distributionTypeId select p).FirstOrDefault();
         if (preference == null)
         {
             preference = new SystemNotificationPreference(notificationTypeId, distributionTypeId, enable);
             defaults.Add(preference);
         }
         else
         {
             preference.IsEnabled = enable;
         }
         DefaultSystemNotifications.UpdateSystemNotificationPreferences(defaults);
     }
 }