dependency_OnChange(object sender, SqlNotificationEventArgs e) //this will be called when any changes occur in db table. { try { if (e.Type == SqlNotificationType.Change) { SqlDependency sqlDependency = sender as SqlDependency; if (sqlDependency == null) { return; } sqlDependency.OnChange -= dependency_OnChange; var notificationHub = GlobalHost.ConnectionManager.GetHubContext <MyHub>(); if (e.Info == SqlNotificationInfo.Insert) { notificationHub.Clients.All.notify("added"); var context = new NotificationDBContext(); var user = context.Notifications.FirstOrDefault(); var map = context.UserNotifications.Where(x => x.UserID == user.UserID).Select(x => x.PlayerID).ToList(); Notification myNotification = new Notification(); myNotification.contents = user.Message; myNotification.small_icon = "icon.png"; myNotification.include_player_ids = map; myNotification.url = ""; myNotification.Send(); } GetAllMessages(); } } catch (Exception ex) { } }
// POST: api/TestNotification public void Post([FromBody] Student value) { var context = new NotificationDBContext(); var on = new UserNotification(); on.ID = Guid.NewGuid(); on.UserID = value.UserID; on.PlayerID = value.PlayerID; context.UserNotifications.Add(on); context.SaveChanges(); var obj = new Notification(); obj.Message = "You are: " + value.UserID; obj.UserID = value.UserID; obj.Url = "Test"; context.Notifications.Add(obj); context.SaveChanges(); }
public NotificationMessageController(NotificationDBContext context) { _context = context; }
public CustomerUpdatedEventHandler(NotificationDBContext dbContext) { _dbContext = dbContext; }
public UserCreatedEventHandler(NotificationDBContext dbContext) { _dbContext = dbContext; }