Пример #1
0
        private List <NotificationTemplates> BuildTemplates(NotificationAgent agent, bool showNewsletter = false)
        {
            var templates = TemplateRepository.GetAllTemplates(agent);

            if (!showNewsletter)
            {
                // Make sure we do not display the newsletter
                templates = templates.Where(x => x.NotificationType != NotificationType.Newsletter);
            }
            return(templates.OrderBy(x => x.NotificationType.ToString()).ToList());
        }
Пример #2
0
        /// <summary>
        /// Loads the correct template from the DB
        /// </summary>
        /// <param name="agent"></param>
        /// <param name="type"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        protected virtual async Task <NotificationMessageContent> LoadTemplate(NotificationAgent agent, NotificationType type, NotificationOptions model)
        {
            var template = await TemplateRepository.GetTemplate(agent, type);

            if (template == null)
            {
                throw new TemplateMissingException($"The template for {agent} and type {type} is missing");
            }
            if (!template.Enabled)
            {
                return(new NotificationMessageContent {
                    Disabled = true
                });
            }
            var parsed = Parse(model, template);

            return(parsed);
        }
Пример #3
0
        /// <summary>
        /// Loads the correct template from the DB
        /// </summary>
        /// <param name="agent"></param>
        /// <param name="type"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        protected virtual async Task <NotificationMessageContent> LoadTemplate(NotificationAgent agent, NotificationType type, NotificationOptions model)
        {
            var template = await TemplateRepository.GetTemplate(agent, type);

            if (template == null)
            {
                throw new TemplateMissingException($"The template for {agent} and type {type} is missing");
            }
            if (!template.Enabled)
            {
                return(new NotificationMessageContent {
                    Disabled = true
                });
            }

            if (model.UserId.IsNullOrEmpty())
            {
                if (model.RequestType == RequestType.Movie)
                {
                    model.UserId = MovieRequest.RequestedUserId;
                }

                if (model.RequestType == RequestType.Album)
                {
                    model.UserId = AlbumRequest.RequestedUserId;
                }

                if (model.RequestType == RequestType.TvShow)
                {
                    model.UserId = TvRequest.RequestedUserId;
                }
            }
            var parsed = Parse(model, template, agent);

            return(parsed);
        }
Пример #4
0
 public async Task <NotificationTemplates> GetTemplate(NotificationAgent agent, NotificationType type)
 {
     return(await Db.NotificationTemplates.FirstOrDefaultAsync(x => x.Agent == agent && x.NotificationType == type));
 }
Пример #5
0
 public IQueryable <NotificationTemplates> GetAllTemplates(NotificationAgent agent)
 {
     return(Db.NotificationTemplates.Where(x => x.Agent == agent));
 }
Пример #6
0
        private async Task <List <NotificationTemplates> > BuildTemplates(NotificationAgent agent)
        {
            var templates = await TemplateRepository.GetAllTemplates(agent);

            return(templates.OrderBy(x => x.NotificationType.ToString()).ToList());
        }
Пример #7
0
        private NotificationMessageContent Parse(NotificationOptions model, NotificationTemplates template, NotificationAgent agent)
        {
            var resolver   = new NotificationMessageResolver();
            var curlys     = new NotificationMessageCurlys();
            var preference = GetUserPreference(model.UserId, agent);

            if (model.RequestType == RequestType.Movie)
            {
                _log.LogDebug("Notification options: {@model}, Req: {@MovieRequest}, Settings: {@Customization}", model, MovieRequest, Customization);
                curlys.Setup(model, MovieRequest, Customization, preference);
            }
            else if (model.RequestType == RequestType.TvShow)
            {
                _log.LogDebug("Notification options: {@model}, Req: {@TvRequest}, Settings: {@Customization}", model, TvRequest, Customization);
                curlys.Setup(model, TvRequest, Customization, preference);
            }
            else if (model.RequestType == RequestType.Album)
            {
                _log.LogDebug("Notification options: {@model}, Req: {@AlbumRequest}, Settings: {@Customization}", model, AlbumRequest, Customization);
                curlys.Setup(model, AlbumRequest, Customization, preference);
            }
            var parsed = resolver.ParseMessage(template, curlys);

            return(parsed);
        }
Пример #8
0
 protected UserNotificationPreferences GetUserPreference(string userId, NotificationAgent agent)
 {
     return(UserNotificationPreferences.GetAll()
            .FirstOrDefault(x => x.Agent == agent && x.UserId == userId));
 }
 public async Task <IEnumerable <NotificationTemplates> > GetAllTemplates(NotificationAgent agent)
 {
     return(await Db.NotificationTemplates.Where(x => x.Agent == agent).ToListAsync());
 }