public async Task <IActionResult> Create([Bind("Id,Name,Price,CreateTime,Store")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); //notify FirebaseNotification noti = new FirebaseNotification(); DataMessage data = new DataMessage() { Data = product, RegistrationIds = new List <string>() { androidDeviceToken, webDeviceToken }, notification = new Notification() { title = product.Name, text = "Name: " + product.Name + "\nPrice: " + product.Price + "\nStore: " + product.Store } }; await noti.SendMessage(data); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <string> Notify(int?id) { var product = await _context.Product .FirstOrDefaultAsync(m => m.Id == id); FirebaseNotification noti = new FirebaseNotification(); DataMessage data = new DataMessage() { Data = product, RegistrationIds = new List <string>() { androidDeviceToken, webDeviceToken }, notification = new Notification() { title = product.Name, text = "Name: " + product.Name + "\nPrice: " + product.Price + "\nStore: " + product.Store } }; string result = await noti.SendMessage(data); return(result); }