public async Task <IActionResult> NotificateAboutChanges(string id, string date) { var product = await _products.GetDocument(id); if (product == null) { return(Content("Данного товара не существует")); } if (product.Subscribers.Count == 0) { return(Content("Никто не отслеживает данный товар")); } foreach (var _id in product.Subscribers) { var subscriber = await _users.GetDocument(_id); var notificationSettings = subscriber.MonitoredProducts.FirstOrDefault(m => m.ProductId == id).NotificationSettings; var productChanges = new ProductChanges() { Price = product.History.FirstOrDefault(p => p.Date == date).Price, Available = product.Available }; var changes = new ChangeTrackingArgs() { UserEmail = subscriber.Email, NotificationSettings = notificationSettings, ProductChanges = productChanges, ProductName = product.Name }; ChangeTracked(changes); } return(Content("Запрос обработан")); }
private void ChangeTrackedHandler(ChangeTrackingArgs args) { string notificationMessage; if (Convert.ToInt32(args.NotificationSettings.NecessaryPrice) >= args.ProductChanges.Price && args.NotificationSettings.Sign == Sign.LessOrEqual || Convert.ToInt32(args.NotificationSettings.NecessaryPrice) <= args.ProductChanges.Price && args.NotificationSettings.Sign == Sign.BiggerOrEqual) { notificationMessage = EmailNotificationSender.GenerateNotificationMessage(args.NotificationSettings.Availability, args.NotificationSettings.PriceChanging, args.ProductChanges.Available, args.ProductChanges.Price, args.ProductName); } else { notificationMessage = EmailNotificationSender.GenerateNotificationMessage(args.NotificationSettings.Availability, args.NotificationSettings.PriceChanging, args.ProductChanges.Available, null, args.ProductName); } _notificationSender.Send(notificationMessage, args.UserEmail); }