public async Task RequestMoneyAid(ActiveUser activeUser) { var user = await _masterRepo.GetUserByIdAsyc(activeUser.Id); if (user.IsMoneyAidProcessing) { throw new BadUserInputException( "the user requested money while there's a waiting request"); } if (user.RequestedMoneyAidToday >= 4) { throw new BadUserInputException( "the user was trying to request money aid above limit"); } if (user.Money >= Room.MinBet) { throw new BadUserInputException( "the user was trying to request money aid while he have enough money"); } //not tested because logic is trivial user.LastMoneyAimRequestTime = DateTime.UtcNow; user.RequestedMoneyAidToday++; // _backgroundJobClient.Schedule(() => MakeMoneyAimClaimable(activeUser.Id), ConstData.MoneyAimTime); await _masterRepo.SaveChangesAsync(); } //trivial to test, best in integration
public async Task RequestRandomRoom(int betChoice, int capacityChoice, ActiveUser activeUser) { if (!betChoice.IsInRange(Room.Bets.Length) || !capacityChoice.IsInRange(Room.Capacities.Length)) { throw new BadUserInputException(); } var dUser = await _masterRepo.GetUserByIdAsyc(activeUser.Id); if (dUser.Money < Room.Bets[betChoice]) { throw new BadUserInputException(); } var room = TakeOrCreateAppropriateRoom(betChoice, capacityChoice); var roomUser = CreateRoomUser(activeUser, room); room.RoomUsers.Add(roomUser); room.RoomActors.Add(roomUser); RemoveDisconnectedUsers(room); if (room.IsFull) { _serverLoop.CancelPendingRoomTimeout(room); await PrepareRoom(room); } else { activeUser.Domain = typeof(UserDomain.App.Lobby.Pending); _serverLoop.SetupPendingRoomTimeoutIfNotExist(room); _sessionRepo.KeepPendingRoom(room); } }
private async Task InitClientGame(ActiveRoomState activeRoomState) { var user = await _masterRepo.GetUserByIdAsyc(Context.UserIdentifier); var clientPersonalInfo = Mapper.ConvertUserDataToClient(user); //you travel to db 2 more times clientPersonalInfo.Followers = await _masterRepo.GetFollowersAsync(Context.UserIdentifier); clientPersonalInfo.Followings = await _masterRepo.GetFollowingsAsync(Context.UserIdentifier); await Clients.Caller.SendAsync("InitGame", ++ActiveUser.MessageIndex, clientPersonalInfo, activeRoomState, ActiveUser.MessageIndex); }
public async Task <User> GetUser() => user ??= await _masterRepo.GetUserByIdAsyc(UserId);