validation!

This commit is contained in:
Wyatt Miller 2018-12-04 14:54:09 -05:00
parent 7a51d60458
commit 7222766e81
12 changed files with 91 additions and 41 deletions

Binary file not shown.

View File

@ -9,21 +9,37 @@ namespace DeskHubSharp
{
class RepoInfo
{
// TODO: Rename this to something more generic
public RepoInfo()
{
}
public List<string> GetRepoInfoDataGrid()
/// <summary>
/// Return a list for the list box
/// </summary>
/// <returns></returns>
public List<string> GetRepoInfoList()
{
List<string> stuff = RequestList.repoDetail.Select(x => x.full_name).ToList();
//stuff =+ RepoList.repoDetail.Select(x => x.name).ToList();
List<string> stuff = new List<string>();
try
{
stuff = RequestList.repoDetail.Select(x => x.full_name).ToList();
}
catch (Exception)
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "We couldn't gather any data. Does the user exist?";
err.ShowDialog();
}
return stuff;
}
// validation
/// <summary>
/// Return a list for the combo box
/// </summary>
/// <returns></returns>
public List<string> GetBranchNameComboBox()
{
List<string> stuff = RequestList.branchDetail.Select(x => x.name).ToList();

View File

@ -56,7 +56,7 @@ namespace DeskHubSharp
// }
//};
if (deserialized.Count() == 0)
if (deserialized.Count == 0)
{
throw new Exception();
}
@ -98,7 +98,7 @@ namespace DeskHubSharp
}
}
catch (Exception)
catch (NullReferenceException)
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "We couldn't gather user data. Please try again.";
@ -123,7 +123,7 @@ namespace DeskHubSharp
RequestList.branchDetail = deserailized;
}
catch (Exception)
catch (NullReferenceException)
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "We couldn't gather user data. Please try again.";

View File

@ -22,6 +22,7 @@ namespace DeskHubSharp
public partial class MainWindow : Window
{
private ObservableCollection<RepoDetail> _repoDetail;
private User _userDetail;
public MainWindow()
{
@ -31,9 +32,26 @@ namespace DeskHubSharp
private void btn_detail_Click(object sender, RoutedEventArgs e)
{
RepoDetail repo = _repoDetail[ListBox.SelectedIndex];
DetailWindow detail = new DetailWindow(repo);
detail.ShowDialog();
try
{
_repoDetail = RequestList.repoDetail;
RepoDetail repo = _repoDetail[ListBox.SelectedIndex];
DetailWindow detail = new DetailWindow(repo);
detail.Show();
}
catch (IndexOutOfRangeException)
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "Please pick a repository!";
err.ShowDialog();
}
catch (NullReferenceException)
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "Please search for a user with the Search button!";
err.ShowDialog();
}
}
private void btn_exit_Click(object sender, RoutedEventArgs e)
@ -62,30 +80,31 @@ namespace DeskHubSharp
private void btn_search_Click(object sender, RoutedEventArgs e)
{
SearchWindow search = new SearchWindow();
search.ShowDialog();
RepoInfo info = new RepoInfo();
Owner owner = new Owner();
search.ShowDialog();
var stuff = info.GetRepoInfoDataGrid();
_repoDetail = RequestList.repoDetail;
ListBox.ItemsSource = stuff;
txtblk_username.Text = RequestList.userDetail.login;
txtblk_url.Text = RequestList.userDetail.html_url;
txtblk_bio.Text = RequestList.userDetail.bio;
txtblk_email.Text = RequestList.userDetail.blog;
txtblk_realname.Text = RequestList.userDetail.name;
txtblk_repocount.Text = $"{RequestList.userDetail.login} has {RequestList.userDetail.public_repos} public repositories.";
//img_avatar.Source = RepoList.repoDetail[0].owner.avatar_url;
var stuff = info.GetRepoInfoList();
if (stuff.Count == 0)
{
txtblk_username.Text = txtblk_username.Text;
txtblk_url.Text = txtblk_url.Text;
txtblk_bio.Text = txtblk_bio.Text;
txtblk_email.Text = txtblk_email.Text;
txtblk_realname.Text = txtblk_realname.Text;
}
else
{
_userDetail = RequestList.userDetail;
ListBox.ItemsSource = stuff;
txtblk_username.Text = _userDetail.login;
txtblk_url.Text = _userDetail.html_url;
txtblk_bio.Text = _userDetail.bio;
txtblk_email.Text = _userDetail.blog;
txtblk_realname.Text = _userDetail.name;
txtblk_repocount.Text = $"{_userDetail.login} has {_userDetail.public_repos} public repositories.";
}
}
private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
//public void ShowDataGridItems()
//{
// DataGrid.ItemsSource = RepoList.repoDetail;
//}
}
}

View File

@ -6,6 +6,8 @@ using System.Threading.Tasks;
namespace DeskHubSharp
{
// TODO: The Owner class is called by code behind, fix it
public class Owner
{
/// <summary>

View File

@ -2,6 +2,8 @@ using DeskHubSharp;
namespace DeskHubSharp
{
// TODO: The RepoDetail class is called from the code behind, fix it
public class RepoDetail
{
public Owner Owner { get; set; }

View File

@ -7,7 +7,8 @@ using System.Threading.Tasks;
namespace DeskHubSharp
{
class RequestList
// TODO: The RequestList class is called from code behind, fix it
public class RequestList
{
public static User userDetail { get; set; }

View File

@ -2,6 +2,8 @@ using System.Collections.Generic;
namespace DeskHubSharp
{
// The User class is called from the code behind, fix it
public class User
{
public string login { get; set; }

View File

@ -31,12 +31,20 @@ namespace DeskHubSharp
private void btn_search_Click(object sender, RoutedEventArgs e)
{
Request request = new Request(txtbox_query.Text);
request.SearchRequest();
request.UserRequest();
//MainWindow main = new MainWindow();
//main.ShowDialog();
this.Close();
if (txtbox_query.Text == "")
{
ErrorWindow err = new ErrorWindow();
err.txtblk_error.Text = "Please enter a username!";
err.ShowDialog();
}
else
{
Request request = new Request(txtbox_query.Text);
request.SearchRequest();
request.UserRequest();
this.Close();
}
}
}
}