예제 #1
0
        public async Task <UserNotificationSettings> Get(string userId)
        {
            var entity = await UserNotificationSettings.Where(o => o.Id == userId)
                         .FirstOrDefaultAsync();

            return(entity?.ToDomain());
        }
예제 #2
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            returnUrl ??= Url.Content("~/");

            if (ModelState.IsValid)
            {
                var userNotificationSettings = new UserNotificationSettings();

                var user = new User
                {
                    FirstName            = model.FirstName,
                    LastName             = model.LastName,
                    UserName             = model.Email,
                    Email                = model.Email,
                    NotificationSettings = userNotificationSettings
                };

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            return(View(model));
        }
        private Notification BuildBrowserNotification(ReportAddedToIncident e, NewSpike countToday,
                                                      UserNotificationSettings setting)
        {
            var notification =
                new Notification(
                    $"Coderr have received {countToday.SpikeCount} reports so far. Day average is {countToday.DayAverage}.")
            {
                Title   = $"Spike detected for {e.Incident.ApplicationName}",
                Actions = new List <NotificationAction>
                {
                    new NotificationAction
                    {
                        Title  = "View",
                        Action = "discoverApplication"
                    }
                },
                Data = new
                {
                    applicationId           = e.Incident.ApplicationId,
                    accountId               = setting.AccountId,
                    discoverApplicationUrlk = $"{_baseConfiguration.BaseUrl}/discover/{e.Incident.ApplicationId}"
                },
                Timestamp = e.Report.CreatedAtUtc
            };

            return(notification);
        }
 public async Task CreateAsync(UserNotificationSettings notificationSettings)
 {
     if (notificationSettings.ApplicationId == 0)
     {
         notificationSettings.ApplicationId = -1;
     }
     await _unitOfWork.InsertAsync(notificationSettings);
 }
예제 #5
0
 public async Task Execute(CreateUserNotificationSettingsDto createUserNotificationSettingsDto)
 {
     string phone    = null;
     var    email    = $"{createUserNotificationSettingsDto.UserName}@popugjira.dev";
     var    slack    = $"@{createUserNotificationSettingsDto.UserName}";
     var    settings = new UserNotificationSettings(createUserNotificationSettingsDto.Id, phone, email, slack);
     await userNotificationSettingsWriteDbOperations.Create(settings);
 }
예제 #6
0
 public async Task Create(UserNotificationSettings settings)
 {
     await UserNotificationSettings.InsertAsync(() => new UserNotificationSettingEntity
     {
         Id            = settings.Id ?? Guid.NewGuid().ToString(),
         PhoneNumber   = settings.PhoneNumber,
         Email         = settings.Email,
         SlackNickname = settings.SlackNickname
     });
 }
예제 #7
0
 private UserNotification Create(UserNotificationSettings settings, Notification notification, NotificationKind kind)
 {
     return(new UserNotification
     {
         CreatedAt = DateTimeOffset.UtcNow,
         ExpiredAt = DateTimeOffset.UtcNow.AddDays(7),
         UserId = settings.UserId,
         Kind = kind,
         Notification = notification
     });
 }
예제 #8
0
        public async Task UpdateSettingsAsync(UserNotificationSettings newSettings)
        {
            var currentSettings = await _repository.GetByIdAsync(newSettings.UserId);

            if (currentSettings.HasValue)
            {
                currentSettings.Value.Update(newSettings);
                newSettings = currentSettings.Value;
            }

            await _repository.AddOrUpdateAsync(newSettings);
        }
        private EmailMessage BuildEmail(ReportAddedToIncident e, UserNotificationSettings setting, NewSpike countToday)
        {
            var msg = new EmailMessage(setting.AccountId.ToString())
            {
                Subject  = $"Spike detected for {e.Incident.ApplicationName} ({countToday} reports)",
                HtmlBody =
                    $"We've detected a spike in incoming reports for application <a href=\"{_baseConfiguration.BaseUrl}discover/{e.Incident.ApplicationId}/\">{e.Incident.ApplicationName}</a>\r\n" +
                    "\r\n" +
                    $"We've received {countToday.SpikeCount} reports so far. Day average is {countToday.DayAverage}\r\n" +
                    "\r\n" + "No further spike emails will be sent today for this application."
            };

            return(msg);
        }
        /// <summary>
        ///     Execute a command asynchronously.
        /// </summary>
        /// <param name="command">Command to execute.</param>
        /// <returns>
        ///     Task which will be completed once the command has been executed.
        /// </returns>
        public async Task HandleAsync(IMessageContext context, UpdateNotifications command)
        {
            var settings = await _notificationsRepository.TryGetAsync(command.UserId, command.ApplicationId);

            if (settings == null)
            {
                settings = new UserNotificationSettings(command.UserId, command.ApplicationId);
                await _notificationsRepository.CreateAsync(settings);
            }

            settings.ApplicationSpike = command.NotifyOnPeaks.ConvertEnum <NotificationState>();
            settings.NewIncident      = command.NotifyOnNewIncidents.ConvertEnum <NotificationState>();
            settings.ReopenedIncident = command.NotifyOnReOpenedIncident.ConvertEnum <NotificationState>();
            settings.UserFeedback     = command.NotifyOnUserFeedback.ConvertEnum <NotificationState>();
            await _notificationsRepository.UpdateAsync(settings);
        }
예제 #11
0
 public async Task HandleAsync(SignedUp @event)
 {
     await _handler
     .Run(async() =>
     {
         var user = await _userServiceClient.GetAsync(@event.UserId);
         if (user.HasNoValue)
         {
             throw new ServiceException(OperationCodes.ResourceNotFound,
                                        $"User with id: {@event.UserId} cannot be found");
         }
         var culture  = GetCulture(user.Value.Culture);
         var settings = UserNotificationSettings.Create(@event.UserId,
                                                        user.Value.Email, user.Value.Name, culture);
         await _settingsService.UpdateSettingsAsync(settings);
     })
     .OnError((ex, logger) => logger.Error(ex, $"Error while handling user SignedUp event, userId: {@event.UserId}"))
     .ExecuteAsync();
 }
 public async Task AddOrUpdateAsync(UserNotificationSettings settings)
 => await _database.UserNotificationSettings().AddOrUpdateAsync(settings);
예제 #13
0
 public async Task AddAsync(UserNotificationSettings settings)
 => await _cache.AddAsync(GetCacheKey(settings.UserId), settings);
 public static async Task AddOrUpdateAsync(
     this IMongoCollection <UserNotificationSettings> collection, UserNotificationSettings settings)
 => await collection.ReplaceOneAsync(x => x.UserId == settings.UserId, settings, new UpdateOptions
 {
     IsUpsert = true
 });
 public async Task EditAsync(UserNotificationSettings settings)
 => await _database.UserNotificationSettings().ReplaceOneAsync(x => x.UserId == settings.UserId, settings);
 public async Task AddAsync(UserNotificationSettings settings)
 => await _database.UserNotificationSettings().InsertOneAsync(settings);