public void Post([FromBody] PeopleUser value) { try { string userId = Request.Headers["userId"]; value.UserId = userId; _context.PeopleUsers.Add(value); _context.SaveChanges(); _hubContext.Clients.All.SendAsync("AddUser", value.Id); } catch (Exception) { } }
private async void StartHub() { try { await _hubConnection.StartAsync(); _hubConnection.On <string>("AddUser", (value) => { if (Users.Any(v => v.UserId == value)) { return; } PeopleUser val = GetUser(value); Users.Add(val); OnCollectionChanged(NotifyCollectionChangedAction.Add, val); }); } catch (Exception) { // ignored } }
protected void OnCollectionChanged(NotifyCollectionChangedAction action, PeopleUser item) { CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(action, item)); }