Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improved account page
  • Loading branch information
farthingt committed Apr 6, 2024
1 parent 6519b30 commit 0b27c5b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
2 changes: 2 additions & 0 deletions WebAppCW/MauiProgram.cs
Expand Up @@ -24,13 +24,15 @@ public static MauiApp CreateMauiApp()

builder.Services.AddSingleton<LoginViewModel>();
builder.Services.AddTransient<CreateAccountViewModel>();
builder.Services.AddSingleton<AccountPageViewModel>();
builder.Services.AddTransient<RavenTorViewModel>();
builder.Services.AddTransient<BiblinsCaveViewModel>();
builder.Services.AddTransient<StanageViewModel>();
builder.Services.AddTransient<RoachesViewModel>();

builder.Services.AddSingleton<LoginPage>();
builder.Services.AddTransient<CreateAccountPage>();
builder.Services.AddSingleton<AccountPage>();
builder.Services.AddTransient<RavenTorPage>();
builder.Services.AddTransient<BiblinsCavePage>();
builder.Services.AddTransient<StanagePage>();
Expand Down
44 changes: 44 additions & 0 deletions WebAppCW/ViewModels/AccountPageViewModel.cs
@@ -0,0 +1,44 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows.Input;
using WebAppCW.Models;
using WebAppCW.Services;

namespace WebAppCW.ViewModels
{
public class AccountPageViewModel : ObservableObject
{
private readonly IDataService _dataService;

public string Username { get; set; }
public string Password { get; set; }
public string Email { get; set; }

public ICommand UpdateAccountCommand { get; }

public ICommand DeleteAccountCommand { get; }

public AccountPageViewModel(IDataService dataService)
{
_dataService = dataService;
UpdateAccountCommand = new AsyncRelayCommand(UpdateAccount);
}

private async Task UpdateAccount()
{
User updatedUser = new User
{
Username = Username,
Password = Password,
Email = Email
};

await _dataService.UpdateUser(updatedUser);
}
}
}
15 changes: 14 additions & 1 deletion WebAppCW/Views/AccountPage.xaml
Expand Up @@ -17,8 +17,21 @@
HorizontalOptions="FillAndExpand" />
</HorizontalStackLayout>
<Label
Text="Account Details"
Text="Enter Details to Proceed"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Entry
Text="{Binding Username}"
Placeholder="Username"/>
<Entry
Text="{Binding Password}"
Placeholder="Password" IsPassword="True"/>
<Entry
Text="{Binding Email}"
Placeholder="Email Address"/>
<Button
Text="Update Account"
Command="{Binding OnUpdateCommand}"
HorizontalOptions="FillAndExpand" />
</VerticalStackLayout>
</ContentPage>
12 changes: 9 additions & 3 deletions WebAppCW/Views/AccountPage.xaml.cs
@@ -1,12 +1,18 @@
using WebAppCW.ViewModels;

namespace WebAppCW;

public partial class AccountPage : ContentPage
{
public AccountPage()
public AccountPage(AccountPageViewModel accountPageViewModel)
{
InitializeComponent();
BindingContext = accountPageViewModel;
}
public AccountPage()
{
InitializeComponent();
}

private void OnHomePageClicked(object sender, EventArgs e)
{
Navigation.PushAsync(new MainPage());
Expand All @@ -16,4 +22,4 @@ private void OnLogoutClicked(object sender, EventArgs e)
{
Navigation.PushAsync(new LoginPage());
}
}
}

0 comments on commit 0b27c5b

Please sign in to comment.