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()); }
/// <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); }
/// <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); }
public async Task <NotificationTemplates> GetTemplate(NotificationAgent agent, NotificationType type) { return(await Db.NotificationTemplates.FirstOrDefaultAsync(x => x.Agent == agent && x.NotificationType == type)); }
public IQueryable <NotificationTemplates> GetAllTemplates(NotificationAgent agent) { return(Db.NotificationTemplates.Where(x => x.Agent == agent)); }
private async Task <List <NotificationTemplates> > BuildTemplates(NotificationAgent agent) { var templates = await TemplateRepository.GetAllTemplates(agent); return(templates.OrderBy(x => x.NotificationType.ToString()).ToList()); }
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); }
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()); }