Пример #1
0
        async void _userManager_UserCreated(object sender, GenericEventArgs <User> e)
        {
            var notification = new Notification
            {
                UserId      = e.Argument.Id,
                Category    = "UserCreated",
                Name        = "Welcome to Media Browser!",
                Description = "Check back here for more notifications."
            };

            try
            {
                await _notificationsRepo.AddNotification(notification, CancellationToken.None).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error adding notification", ex);
            }
        }
Пример #2
0
 public Task SendNotification(UserNotification request, CancellationToken cancellationToken)
 {
     return(_repo.AddNotification(new Notification
     {
         Date = request.Date,
         Description = request.Description,
         Level = request.Level,
         Name = request.Name,
         Url = request.Url,
         UserId = request.User.Id.ToString("N")
     }, cancellationToken));
 }
Пример #3
0
        /// <summary>
        /// Asynchronous method that adds a Notification class to the context
        /// </summary>
        /// <param name="id"></param>
        /// <param name="delivererId"></param>
        /// <param name="deliveryId"></param>
        /// <param name="createdAt"></param>
        /// <param name="expiredAt"></param>
        /// <param name="status"></param>
        /// <returns>true or false</returns>
        public async Task <bool> AddNotification(Guid id, Guid delivererId, Guid deliveryId, DateTime createdAt, DateTime expiredAt, NotificationStatus status)
        {
            try
            {
                _logger.Information($"A request has been made to add a Notification with id {id} to the context.");
                bool result = await _notificationsRepo.AddNotification(id, delivererId, deliveryId, createdAt, expiredAt, status);

                return(result ? result : throw new Exception($"Dependency failure: The repository returned false."));
            }
            catch (Exception e) // Error handling
            {
                _logger.Error($"INotificationsService says: {e.Message} Exception occured on line " +
                              $"{new StackTrace(e, true).GetFrame(0).GetFileLineNumber()}.");
                return(false);
            }
        }
        private async Task <Notification> AddNotification(AddNotification request)
        {
            var notification = new Notification
            {
                Id          = request.Id ?? Guid.NewGuid(),
                Date        = DateTime.UtcNow,
                Description = request.Description,
                Level       = request.Level,
                Name        = request.Name,
                Url         = request.Url,
                UserId      = request.UserId,
                Category    = request.Category,
                RelatedId   = request.RelatedId
            };

            await _notificationsRepo.AddNotification(notification, CancellationToken.None).ConfigureAwait(false);

            return(notification);
        }