Exemple #1
0
        // Gets games from Rawg Database
        public async Task <IGameRootObject> GetGames(string search, HomePage.ErrorHandling errorMessage)
        {
            // Checks connection
            bool connection = _checkConnection.hasConnection(errorMessage);

            if (connection)
            {
                // This is short hand for the below code, this makes it more difficult for me and reduces the amount of If statements greatly
                // Could be shortened even more but it would look much more confusing after removing yet another if statement
                return(!string.IsNullOrEmpty(search) ? await _gameProxy.GetGameBySearch(search, errorMessage) ?? null : await _gameProxy.GetAllGameInfo(errorMessage) ?? null);

                // Original Code

                // If it has something to search for
                //if (!string.IsNullOrEmpty(search))
                //{
                //    // Gets games by search
                //    var games = await _gameProxy.GetGameBySearch(search, errorMessage);
                //    return games ?? null;

                //}
                //else // If their is no input it should grab all games
                //{
                //    // Gets all games
                //    var games = await _gameProxy.GetAllGameInfo(errorMessage);
                //    return games ?? null;
                //}
            }
            else
            {
                return(null);
            }
        }
        // Gets the user info (Logs them in)
        public async Task <IUser> GetUser(string uName, string password, HomePage.ErrorHandling errorMessage)
        {
            // Checks connection
            bool connection = _checkConnection.hasConnection(errorMessage);

            if (connection)
            {
                // Grabs the user info by their username and password
                IUser user = await _userProxy.GetUser(errorMessage, uName, password);

                if (user != null) // Checks that its not null
                {
                    // If they want their details to be remembered it saves the data locally
                    if (await Storage.ReadTextFileAsync(App.detailsLocation, errorMessage) == "true")
                    {
                        await Storage.WriteTextFileAsync(App.uNameLocation, user.UName, errorMessage);

                        await Storage.WriteTextFileAsync(App.pwrdLocation, user.Pwrd, errorMessage);
                    }

                    return(user); // Return the user
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        // Get the wishlist
        public async Task <List <Game> > GetWishlist(HomePage.ErrorHandling errorMessage, string id)
        {
            // Checks the internet connection
            bool connection = _checkConnection.hasConnection(errorMessage);

            if (connection)
            {
                // Checks the id isnt null
                if (id != null)
                {
                    // Gets the wishlist
                    var items = await _wishlistPlayedProxy.GetItems <Wishlist>(errorMessage, "Wishlist", id);

                    // If it was able to get items back
                    if (items != null)
                    {
                        List <Game> games = new List <Game>();

                        // Gets all the games asociated with the wishlist gameID
                        // Since MongoDB cant do inner joins this was the closest thing i could do
                        foreach (var item in items)
                        {
                            // Each item in the wishlist a search will be made that grabs the game matching its ID
                            games.Add((Game)await _customGameProxy.GetGameByID(errorMessage, item.GameID));
                        }
                        return(games);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    // Using my delegate it will return the error message that the user must be logged in
                    errorMessage("Must be logged in");
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
        // This method updates the user details
        public async Task <bool> UpdateUser(User user, HomePage.ErrorHandling errorMessage)
        {
            // This is a short hand form of the code below, I learnt to do it this way to shorten down code and challenge myself to minimize my code
            return(_checkConnection.hasConnection(errorMessage) ? await _userProxy.PutUser(errorMessage, user) : false);

            // Original Code

            //bool connection = _checkConnection.hasConnection(errorMessage);
            //if (connection)
            //    return await _userProxy.PutUser(errorMessage, user);
            //else
            //    return false;
        }
Exemple #5
0
 // Retrieves a single game from the RAWG Api //
 public async Task <ISingleGameRootObject> GetGame(string slug, HomePage.ErrorHandling errorMessage) =>
 // First checks if there is a connection
 // If there is a connection it will Get the Game info from the API
 // The ?? checks if the item is null, if its null then it will return null, if its not null then it will return the ISingleGameRoot Object
 // Finally if the there is no connection then this method returns null
 _checkConnection.hasConnection(errorMessage) ? await _gameProxy.GetSinlgeGameInfo(slug, errorMessage) ?? null : null;
Exemple #6
0
 // Registers the user
 public async Task <bool> RegisterUser(HomePage.ErrorHandling errorMessage, User user) =>
 // Checks if there is a connection
 // If there is then it will try to post a user and return true or false based wether the user was able to be posted or not
 // If there is no connection then it returns false
 _checkConnection.hasConnection(errorMessage) ? await _userProxy.PostUser(errorMessage, user) : false;