Skip to content
Permalink
Browse files
Improved account page
  • Loading branch information
farthingt committed Apr 6, 2024
1 parent 6519b30 commit 0b27c5b52bcea07d0bbac363dfeae4fcb8b2be30
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
@@ -24,13 +24,15 @@ namespace WebAppCW

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>();
@@ -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);
}
}
}
@@ -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>
@@ -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());
@@ -16,4 +22,4 @@ public partial class AccountPage : ContentPage
{
Navigation.PushAsync(new LoginPage());
}
}
}

0 comments on commit 0b27c5b

Please sign in to comment.