public async Task <Session> StartOrJoin(StartJoinSessionRequest request) { if (string.IsNullOrEmpty(request.SessionId)) { //Create Session var session = new Session(); if (request.User != null) { session.Users.Add(request.User); await _context.AddAsync(session); await _context.SaveChangesAsync(); } return(session); } else { //Look up and join session var session = await _context.FindAsync <Session>(request.SessionId); session.Users.Add(request.User); _context.Update(session); await _context.SaveChangesAsync(); return(session); } }
public async Task SendPoints(string sessionId, string userId, int points) { var entity = _context.Sessions.FirstOrDefault(item => item.Id == sessionId); entity.Users.Find(u => u.Id == userId).Points = points; _context.Entry(entity).State = Microsoft.EntityFrameworkCore.EntityState.Detached; _context.Update(entity); await _context.SaveChangesAsync(); await Clients.All.SendAsync("ReceivePoints", userId, points); }