Adding final project to dev branch
This commit is contained in:
79
WguApp/Views/HomePage.xaml.cs
Normal file
79
WguApp/Views/HomePage.xaml.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WguApp.Controls;
|
||||
using WguApp.Models;
|
||||
using WguApp.Services;
|
||||
|
||||
namespace WguApp.Views;
|
||||
|
||||
public partial class HomePage : ContentPage
|
||||
{
|
||||
|
||||
private List<Term> _terms = [];
|
||||
|
||||
public HomePage()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_ = RefreshTermList();
|
||||
}
|
||||
|
||||
private async Task RefreshTermList()
|
||||
{
|
||||
_terms.Clear();
|
||||
_terms = await DatabaseService.GetAllTerms();
|
||||
|
||||
TermButtonStack.Children.Clear();
|
||||
|
||||
|
||||
|
||||
foreach (var term in _terms)
|
||||
{
|
||||
var btn = new CustomButton()
|
||||
{
|
||||
Text = term.Name,
|
||||
DateText = $"{DateOnly.FromDateTime(term.StartDate).ToString()} - {DateOnly.FromDateTime(term.EndDate).ToString()}"
|
||||
};
|
||||
|
||||
TermButtonStack.Add(btn);
|
||||
|
||||
btn.Clicked += (sender, e) =>
|
||||
{
|
||||
HandleTermButtonClick(term);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async void AddTermButton_OnClicked(object? sender, EventArgs e)
|
||||
{
|
||||
var newTerm = new Term()
|
||||
{
|
||||
Name = "New Term",
|
||||
StartDate = DateTime.Today,
|
||||
EndDate = DateTime.Today.AddDays(30)
|
||||
};
|
||||
|
||||
await DatabaseService.AddTerm(newTerm);
|
||||
|
||||
await RefreshTermList();
|
||||
}
|
||||
|
||||
protected override async void OnNavigatedTo(NavigatedToEventArgs args)
|
||||
{
|
||||
await RefreshTermList();
|
||||
}
|
||||
|
||||
private void HandleTermButtonClick(Term term)
|
||||
{
|
||||
Navigation.PushAsync(new TermPage(term));
|
||||
}
|
||||
|
||||
private void TestButton_OnClicked(object? sender, EventArgs e)
|
||||
{
|
||||
Navigation.PushAsync(new TestPage());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user