public Tuple <Score, MazeSolution> GetUserSolution(Guid mazeId, string userId) { Guid userGuid = new Guid(userId); UserMaze um = _userMazeRepository.FindById(mazeId, userGuid); if (um == null) { throw new ApiException(404, "User solution not found"); } string userSolution = um.UserSolution.DecompressString(); Maze maze = _mazeRepository.FindById(mazeId); MazeSolution sol = new MazeSolution(userSolution, maze.Width, '4'); Score userAccuracy = new Score(um.Accuracy.GetValueOrDefault()); return(new Tuple <Score, MazeSolution>(userAccuracy, sol)); }
private UserDTO BuildUserDTOFromUser(User user) { user.UserMazes = _userMazeRepository.FindOwnMazesByUserId(user.UserId); List <MazeDTO> ownMazes = new List <MazeDTO>(); foreach (UserMaze um in user.UserMazes) { Maze m = _mazeRepository.FindById(um.MazeId); int playersCount = _userMazeRepository.PlayersCountByMazeId(m.MazeId); MazeDTO mDTO = MazeDTO.Builder() .Id(m.MazeId) .Name(m.Name) .PlayersCount(playersCount) .Width(m.Width) .Height(m.Height) .State(m.State.DecompressString()) .CreationTime(m.CreationTime) .Build(); ownMazes.Add(mDTO); } List <UserMaze> solvedMazes = _userMazeRepository.FindLockedMazesByUserId(user.UserId); int totalAccuracy = 0; foreach (UserMaze um in solvedMazes) { totalAccuracy += um.Accuracy.GetValueOrDefault(); } int accuracy = 0; if (solvedMazes.Count != 0) { accuracy = totalAccuracy / solvedMazes.Count; } return(UserDTO.Builder() .Id(user.UserId) .Username(user.Username) .Accuracy(accuracy) .OwnMazes(ownMazes) .SolvedMazesCount(solvedMazes.Count) .Build()); }