From 0b27c5b52bcea07d0bbac363dfeae4fcb8b2be30 Mon Sep 17 00:00:00 2001 From: farthingt Date: Sat, 6 Apr 2024 14:43:22 +0100 Subject: [PATCH] Improved account page --- WebAppCW/MauiProgram.cs | 2 + WebAppCW/ViewModels/AccountPageViewModel.cs | 44 +++++++++++++++++++++ WebAppCW/Views/AccountPage.xaml | 15 ++++++- WebAppCW/Views/AccountPage.xaml.cs | 12 ++++-- 4 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 WebAppCW/ViewModels/AccountPageViewModel.cs diff --git a/WebAppCW/MauiProgram.cs b/WebAppCW/MauiProgram.cs index 68e8de9..5d7db6d 100644 --- a/WebAppCW/MauiProgram.cs +++ b/WebAppCW/MauiProgram.cs @@ -24,6 +24,7 @@ namespace WebAppCW builder.Services.AddSingleton(); builder.Services.AddTransient(); + builder.Services.AddSingleton(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); @@ -31,6 +32,7 @@ namespace WebAppCW builder.Services.AddSingleton(); builder.Services.AddTransient(); + builder.Services.AddSingleton(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/WebAppCW/ViewModels/AccountPageViewModel.cs b/WebAppCW/ViewModels/AccountPageViewModel.cs new file mode 100644 index 0000000..fef12dc --- /dev/null +++ b/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); + } + } +} diff --git a/WebAppCW/Views/AccountPage.xaml b/WebAppCW/Views/AccountPage.xaml index c29689f..caab5e1 100644 --- a/WebAppCW/Views/AccountPage.xaml +++ b/WebAppCW/Views/AccountPage.xaml @@ -17,8 +17,21 @@ HorizontalOptions="FillAndExpand" />