Ejemplo n.º 1
0
        public static UserNotificationChannelDto FromDomainObject(UserNotificationChannel source)
        {
            var result = SimpleMapper.Map(source, new UserNotificationChannelDto
            {
                Status = new Dictionary <string, ChannelSendInfoDto>()
            });

            if (source.Setting != null)
            {
                result.Setting = ChannelSettingDto.FromDomainObject(source.Setting);
            }
            else
            {
                result.Setting = new ChannelSettingDto();
            }

            if (source.Status != null)
            {
                foreach (var(key, value) in source.Status)
                {
                    result.Status[key] = ChannelSendInfoDto.FromDomainObject(value);
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static TemplateDto FromDomainObject(Template source)
        {
            var result = SimpleMapper.Map(source, new TemplateDto());

            if (source.Formatting != null)
            {
                result.Formatting = NotificationFormattingDto.FromDomainObject(source.Formatting);
            }
            else
            {
                result.Formatting = new NotificationFormattingDto();
            }

            if (source.Settings != null)
            {
                foreach (var(key, value) in source.Settings)
                {
                    if (value != null)
                    {
                        result.Settings[key] = ChannelSettingDto.FromDomainObject(value);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static EventDto FromDomainObject(Event source, App app)
        {
            var result = SimpleMapper.Map(source, new EventDto
            {
                Settings = new Dictionary <string, ChannelSettingDto>()
            });

            result.Properties = source.Properties ?? EmptyProperties;

            if (source.Formatting.Subject.TryGetValue(app.Language, out var subject))
            {
                result.DisplayName = subject;
            }
            else
            {
                result.DisplayName = source.Formatting.Subject.Values.FirstOrDefault() ?? string.Empty;
            }

            if (source.Formatting != null)
            {
                result.Formatting = NotificationFormattingDto.FromDomainObject(source.Formatting);
            }

            if (source.Scheduling != null)
            {
                result.Scheduling = SchedulingDto.FromDomainObject(source.Scheduling);
            }

            if (source.Settings?.Count > 0)
            {
                result.Settings = new Dictionary <string, ChannelSettingDto>();

                foreach (var(key, value) in source.Settings)
                {
                    if (value != null)
                    {
                        result.Settings[key] = ChannelSettingDto.FromDomainObject(value);
                    }
                }
            }
            else
            {
                result.Settings = EmptySettings;
            }

            result.Counters = source.Counters ?? EmptyCounters;

            return(result);
        }
Ejemplo n.º 4
0
        public static ProfileDto FromDomainObject(User source, App app)
        {
            var result = SimpleMapper.Map(source, new ProfileDto());

            result.SupportedTimezones = DateTimeZoneProviders.Tzdb.Ids.ToArray();
            result.SupportedLanguages = app.Languages.ToArray();

            if (source.Settings != null)
            {
                foreach (var(key, value) in source.Settings)
                {
                    if (value != null)
                    {
                        result.Settings[key] = ChannelSettingDto.FromDomainObject(value);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
        public static SubscriptionDto FromDomainObject(Subscription subscription)
        {
            var result = new SubscriptionDto
            {
                TopicPrefix = subscription.TopicPrefix
            };

            if (subscription.TopicSettings != null)
            {
                foreach (var(key, value) in subscription.TopicSettings)
                {
                    if (value != null)
                    {
                        result.TopicSettings[key] = ChannelSettingDto.FromDomainObject(value);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
        public static UserDto FromDomainObject(User source, List <UserProperty>?properties, IReadOnlyDictionary <string, Instant>?lastNotifications)
        {
            var result = SimpleMapper.Map(source, new UserDto());

            if (source.Settings != null)
            {
                foreach (var(key, value) in source.Settings)
                {
                    if (value != null)
                    {
                        result.Settings[key] = ChannelSettingDto.FromDomainObject(value);
                    }
                }
            }

            foreach (var subscription in source.WebPushSubscriptions.OrEmpty())
            {
                result.WebPushSubscriptions.Add(WebPushSubscriptionDto.FromDomainObject(subscription));
            }

            foreach (var token in source.MobilePushTokens.OrEmpty())
            {
                result.MobilePushTokens.Add(MobilePushTokenDto.FromDomainObject(token));
            }

            if (properties != null)
            {
                result.UserProperties = properties.Select(UserPropertyDto.FromDomainObject).ToList();
            }

            result.Counters = source.Counters ?? EmptyCounters;

            if (lastNotifications != null && lastNotifications.TryGetValue(source.Id, out var lastNotification))
            {
                result.LastNotification = lastNotification;
            }

            return(result);
        }