public string InviteUserToBoard(string fromUser, string toUser, Guid boardId) { var result = new Result(); try { using (var db = new WeSketchDataContext()) { var context = GlobalHost.ConnectionManager.GetHubContext <WeSketchSignalRHub>(); var invitee = db.Users.SingleOrDefault(usr => usr.UserName == toUser); if (invitee != null) { context.Clients.Group(invitee.UserID.ToString()).ReceiveInvitation(fromUser, boardId); } else { throw new Exception($"User {toUser} does not exist. Please check spelling and try again."); } } } catch (Exception e) { result.Error = true; result.ErrorMessage = e.Message; } return(JsonConvert.SerializeObject(result)); }
public string JoinBoard(Guid userId, string userName, string hostUser) { var result = new Result(); var board = new Board(); try { using (var db = new WeSketchDataContext()) { var user = db.Users.Single(usr => usr.UserName == userName); if (user.UserID == userId) { var host = db.Users.Single(usrHost => usrHost.UserName == hostUser); user.UserBoard.BoardID = host.UserBoard.BoardID; user.UserBoard.BoardOwner = false; user.UserBoard.CanSketch = false; db.SubmitChanges(); board.BoardID = host.UserBoard.BoardID; board.Owner = false; result.ResultJSON = JsonConvert.SerializeObject(board); } else { throw new Exception("Invalid user."); } } } catch (Exception e) { result.Error = true; result.ErrorMessage = e.Message; } return(JsonConvert.SerializeObject(result)); }