// handles getting a user from the client over ws, then upserts them, and send the information back to all the clients through a reusable method. public void SendUser(Strengths.Shared.Models.User user) { User _existingUser = _strengthsContext.Users.SingleOrDefault(u => u.FirstName == user.FirstName && u.LastName == user.LastName); if (_existingUser != null) { _existingUser.Theme1 = _strengthsContext.Themes.Find(user.Theme1.Id); _existingUser.Theme2 = _strengthsContext.Themes.Find(user.Theme2.Id); _existingUser.Theme3 = _strengthsContext.Themes.Find(user.Theme3.Id); _existingUser.Theme4 = _strengthsContext.Themes.Find(user.Theme4.Id); _existingUser.Theme5 = _strengthsContext.Themes.Find(user.Theme5.Id); _strengthsContext.SaveChanges(); } else { user.Id = 0; user.Theme1 = _strengthsContext.Themes.Include(t => t.Domain).SingleOrDefault(t => t.Id == user.Theme1.Id); user.Theme2 = _strengthsContext.Themes.Include(t => t.Domain).SingleOrDefault(t => t.Id == user.Theme2.Id); user.Theme3 = _strengthsContext.Themes.Include(t => t.Domain).SingleOrDefault(t => t.Id == user.Theme3.Id); user.Theme4 = _strengthsContext.Themes.Include(t => t.Domain).SingleOrDefault(t => t.Id == user.Theme4.Id); user.Theme5 = _strengthsContext.Themes.Include(t => t.Domain).SingleOrDefault(t => t.Id == user.Theme5.Id); _strengthsContext.Users.Add(user); _strengthsContext.SaveChanges(); } this.Send(user); }
public void Send(Strengths.Shared.Models.User user) { // reusable method to send an object to all clients over ws Clients.All.SendAsync("broadcastUser", user); }