public async Task Handle(ClientServiceAddedEvent message) // Notify the owner of the shop. { var notification = new NotificationAggregate { Id = Guid.NewGuid().ToString(), Content = "create_client_service", CreatedDateTime = DateTime.UtcNow, IsRead = false, From = message.Subject, To = message.Subject, Parameters = new[] { new NotificationParameter { Id = Guid.NewGuid().ToString(), Type = NotificationParameterTypes.ClientServiceId, Value = message.Id } } }; await _notificationRepository.Add(notification); _eventPublisher.Publish(new NotificationAddedEvent { Id = notification.Id, Content = notification.Content, IsRead = notification.IsRead, From = notification.From, To = notification.To }); }
public async Task Handle(OrderCanceledEvent message) { var notification = new NotificationAggregate { Id = Guid.NewGuid().ToString(), Content = "order_label_canceled", IsRead = false, From = message.SellerId, To = message.Subject, CreatedDateTime = DateTime.UtcNow, Parameters = new[] { new NotificationParameter { Id = Guid.NewGuid().ToString(), Type = NotificationParameterTypes.OrderId, Value = message.OrderId } } }; await _notificationRepository.Add(notification); _eventPublisher.Publish(new NotificationAddedEvent { Id = notification.Id, Content = notification.Content, IsRead = notification.IsRead, From = notification.From, To = notification.To }); }
public async Task Handle(ProductAddedEvent message) { var shop = await _shopRepository.Get(message.ShopId); var notification = new NotificationAggregate { Id = Guid.NewGuid().ToString(), Content = "add_product", CreatedDateTime = DateTime.UtcNow, IsRead = false, From = shop.Subject, To = shop.Subject, Parameters = new[] { new NotificationParameter { Id = Guid.NewGuid().ToString(), Type = NotificationParameterTypes.ProductId, Value = message.Id } } }; await _notificationRepository.Add(notification); _eventPublisher.Publish(new NotificationAddedEvent { Id = notification.Id, Content = notification.Content, IsRead = notification.IsRead, From = notification.From, To = notification.To }); }
public async Task Handle(MessageAddedEvent message) // Notify the "to" that a message has been sent. { var notification = new NotificationAggregate { Id = Guid.NewGuid().ToString(), Content = "add_message", IsRead = false, From = message.From, To = message.To, CreatedDateTime = DateTime.UtcNow, Parameters = new[] { new NotificationParameter { Id = Guid.NewGuid().ToString(), Type = NotificationParameterTypes.MessageId, Value = string.IsNullOrWhiteSpace(message.ParentId) ? message.Id : message.ParentId } } }; await _notificationRepository.Add(notification); _eventPublisher.Publish(new NotificationAddedEvent { Id = notification.Id, Content = notification.Content, IsRead = notification.IsRead, From = notification.From, To = notification.To }); }
public async Task <bool> Add(NotificationAggregate notification) { if (notification == null) { throw new ArgumentNullException(nameof(notification)); } using (var transaction = await _context.Database.BeginTransactionAsync().ConfigureAwait(false)) { try { var record = notification.ToModel(); _context.Notifications.Add(record); await _context.SaveChangesAsync().ConfigureAwait(false); transaction.Commit(); return(true); } catch { transaction.Rollback(); return(false); } } }
public async Task <bool> Update(NotificationAggregate notification) { if (notification == null) { throw new ArgumentNullException(nameof(notification)); } using (var transaction = await _context.Database.BeginTransactionAsync().ConfigureAwait(false)) { try { var record = await _context.Notifications.FirstOrDefaultAsync(n => n.Id == notification.Id).ConfigureAwait(false); if (record == null) { transaction.Rollback(); return(false); } record.IsRead = notification.IsRead; await _context.SaveChangesAsync().ConfigureAwait(false); transaction.Commit(); return(true); } catch { transaction.Rollback(); return(false); } } }
public void Enrich(IHalResponseBuilder halResponseBuilder, NotificationAggregate notification) { if (halResponseBuilder == null) { throw new ArgumentNullException(nameof(halResponseBuilder)); } if (notification == null) { throw new ArgumentNullException(nameof(notification)); } halResponseBuilder.AddEmbedded(e => e.AddObject(_responseBuilder.GetNotification(notification), (l) => { l.AddSelf(Constants.RouteNames.Notifications + "/" + notification.Id); })); }
public static Notification ToModel(this NotificationAggregate notification) { if (notification == null) { throw new ArgumentNullException(nameof(notification)); } var parameters = notification.Parameters.Select(p => p.ToModel()).ToList(); return(new Notification { Id = notification.Id, Content = notification.Content, CreatedDateTime = notification.CreatedDateTime, From = notification.From, To = notification.To, IsRead = notification.IsRead, Parameters = parameters }); }
public UpdateNotificationValidationResult(NotificationAggregate notification) { Notification = notification; IsValid = true; }