/// <summary>
        /// Fires when the user expresses intent to login.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            logginText.Text = "Please hold on!";
            string username = LoginNameTextBox.Text; //get the username

            string password = LoginPassTextBox.Text; //get the password.

            string endpoint = @"https://api.africoders.com/v1/user/login?name=" + username + "&password="******"Log in user");

            string result = await africoders.AuthenticateLoginAndRegAsync(username, password);

            if (result == "OK")
            {
                MessageBoxResult messageBoxResult = MessageBox.Show("Proceed to your Africoders Page?", "User successfully Authenticated", MessageBoxButton.YesNo, MessageBoxImage.Question);
                switch (messageBoxResult)
                {
                case MessageBoxResult.Yes:
                    break;

                case MessageBoxResult.No:
                    return;
                }

                logginText.Text = "Successfully signed in!";
                //Now, we have to get the success json returned from the server.
                //This result contains all the important information about the currently signed-in user.
                string             successJsonResult  = africoders.SuccessJSON;
                LoginReturnService loginReturnService = null;
                //Carefully deserialise the json result using the login return service class.
                if (successJsonResult != null)
                {
                    loginReturnService = JsonConvert.DeserializeObject <LoginReturnService>(successJsonResult);
                }
                //MessageBox.Show(loginReturnService.status + " " + loginReturnService.token);

                //Carefully load the africoders page
                AfricodersPage africodersPage = new AfricodersPage();

                africodersPage.WelcomeControl.username.Text = loginReturnService.data.Select(x => x.name).FirstOrDefault();

                var bitmap = new BitmapImage(new Uri(loginReturnService.data.Select(x => x.avatarUrl).FirstOrDefault()));

                africodersPage.WelcomeControl.profilePicture.Source = bitmap;

                africodersPage.currentPageTextBlock.Text = "Welcome " + username + " !";

                //IMPORTANT

                //SET THE TOKEN FOR THE STATUS CONTROL
                africodersPage.statusControl.Token = loginReturnService.token;//GET THE TOKEN FOR THE AUTHENTICATED USER.

                //SET TOKEN FOR THE BLOG CONTROL
                africodersPage.blogControl.Token = loginReturnService.token;

                //Set token for the Jobs control.
                africodersPage.theJobsControl.Token = loginReturnService.token;

                //Set token for the links control.
                africodersPage.theLinksControl.Token = loginReturnService.token;

                //Set token for the individual forum control.
                africodersPage.theIndividualForumControl.Token = loginReturnService.token;
                //Here set all profile information accordingly.
                //Profile picture
                africodersPage.theProfilePage.ProfilePicture.Source = bitmap;
                //Nickname
                africodersPage.theProfilePage.nickNameText.Text = loginReturnService.data.Select(x => x.name).FirstOrDefault() ?? "Not set.";
                //firstname
                africodersPage.theProfilePage.firstNameText.Text = loginReturnService.data.Select(f => f.first).FirstOrDefault() ?? "Not set.";
                //lastName
                africodersPage.theProfilePage.lastNameText.Text = loginReturnService.data.Select(l => l.last).FirstOrDefault() ?? "Not set.";
                //Phone
                africodersPage.theProfilePage.phoneText.Text = loginReturnService.data.Select(p => p.phone).FirstOrDefault() ?? "Not set.";
                //Email
                africodersPage.theProfilePage.emailText.Text = loginReturnService.data.Select(em => em.email).FirstOrDefault() ?? "Not set.";
                //gender
                africodersPage.theProfilePage.genderText.Text = loginReturnService.data.Select(gd => gd.gender).FirstOrDefault() ?? "Not set.";
                //location
                africodersPage.theProfilePage.locationText.Text = loginReturnService.data.Select(lc => lc.location).FirstOrDefault() ?? "Not set.";
                //occupation
                africodersPage.theProfilePage.occupationText.Text = loginReturnService.data.Select(oc => oc.occupation).FirstOrDefault() ?? "Not set.";
                //birthday
                africodersPage.theProfilePage.birthdayText.Text = loginReturnService.data.Select(bd => bd.birthdate).FirstOrDefault() ?? "Not set.";
                //company
                africodersPage.theProfilePage.companyText.Text = loginReturnService.data.Select(com => com.company).FirstOrDefault() ?? "Not set.";

                //Get the ID of the authorised user. This is very important.
                int generalID = loginReturnService.data.Select(x => x.id).FirstOrDefault();
                africodersPage.ID = generalID;


                //MessageBox.Show(africodersPage.ID.ToString());
                //Propagate the ID across all controls.

                africodersPage.statusControl.LoggedID = generalID;

                africodersPage.theJobsControl.LoggedId = generalID;

                africodersPage.theLinksControl.LoggedID = generalID;

                africodersPage.blogControl.LoggedID = generalID;

                africodersPage.theIndividualForumControl.LoggedID = generalID;

                africodersPage.forumControl.UserID = generalID;
                //Set the top proile image
                africodersPage.topProfileImage.Source = bitmap;
                africodersPage.topIconImage.ToolTip   = loginReturnService.data.Select(n => n.name).FirstOrDefault();
                africodersPage.Show();

                //Hide the main window
                MainWindow mainWindow = Window.GetWindow(Parent) as MainWindow;
                africodersPage.mainWindow = mainWindow;
                mainWindow.Hide();
            }
            else
            {
                logginText.Text = "Authentication Failed!. Consider trying again.";
                MessageBox.Show("Unable to authenticate user because: " + "\n" + result);
            }
        }
        /// <summary>
        /// Button to handle the open forum event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OpenButton_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;
            //Get the categrory
            MultiCategory multiCategory = (MultiCategory)btn.DataContext;
            //Get the category
            string path = multiCategory.path;
            //Get the real endpoint

            //MessageBox.Show(path);

            //After clicking the button, it is important to send messgae to the africoders window.
            AfricodersPage africodersPage = Window.GetWindow(Parent) as AfricodersPage;

            //Close all exisitng controls.
            africodersPage.theProfilePage.Visibility  = Visibility.Hidden;
            africodersPage.WelcomeControl.Visibility  = Visibility.Hidden;
            africodersPage.blogControl.Visibility     = Visibility.Hidden;
            africodersPage.statusControl.Visibility   = Visibility.Hidden;
            africodersPage.toolsControl.Visibility    = Visibility.Hidden;
            africodersPage.theLinksControl.Visibility = Visibility.Hidden;
            africodersPage.theJobsControl.Visibility  = Visibility.Hidden;
            africodersPage.forumControl.Visibility    = Visibility.Hidden;
            //Only the individual forum control should be alive.
            africodersPage.currentPageTextBlock.Text = "Forum " + multiCategory.board;

            africodersPage.theIndividualForumControl.Path = multiCategory.path;
            //Set the forum ID
            africodersPage.theIndividualForumControl.FID = multiCategory.fid;

            try
            {
                africodersPage.temporaryBlogGrid.Visibility = Visibility.Visible;

                africodersPage.FetchText.Text = "Loading " + multiCategory.board + " forum";
                string endPoint = @"https://api.africoders.com/v1/" + path + "?page=1" + "&order=updated_at|DESC&include=comment";

                jsonObtainer = new JsonObtainer(endPoint, "Forum_Agent_Bolkay");

                string json = await jsonObtainer.GetJsonStringAsync();

                //Changed the explicit Individual forum to dynamic
                IndividualForum individualForum = JsonConvert.DeserializeObject <IndividualForum>(json);

                foreach (var dat in individualForum.data)
                {
                    //Reformat the time format.
                    string date = dat.created.date;

                    string convertedTime = Convert.ToDateTime(DateTime.Parse(date)).ToString(("ddd, dd MMM yyyy hh:mm:tt"));
                    dat.created.date = convertedTime;

                    dat.LoggedInID = UserID;
                }

                africodersPage.theIndividualForumControl.TheListBox.ItemsSource = individualForum.data;

                africodersPage.temporaryBlogGrid.Visibility = Visibility.Hidden;
                //Carefully transfer the path to the individual forum

                africodersPage.theIndividualForumControl.Visibility = Visibility.Visible;
            }
            catch (Exception t)
            {
                MessageBox.Show(t.Message);
                africodersPage.forumControl.Visibility = Visibility.Visible;
                africodersPage.theIndividualForumControl.Visibility = Visibility.Hidden;
                africodersPage.temporaryBlogGrid.Visibility         = Visibility.Hidden;

                MessageBox.Show("Unable to show " + multiCategory.category + " at this time.");
            }
        }