using System; using System.Reactive; using System.Threading.Tasks; using Avalonia; using Flawless.Client.Remote; using Flawless.Client.Service; using ReactiveUI; using ReactiveUI.SourceGenerators; using Refit; namespace Flawless.Client.ViewModels; public partial class RegisterPageViewModel : ViewModelBase, IRoutableViewModel { public string? UrlPathSegment { get; } = Guid.NewGuid().ToString(); public IScreen HostScreen { get; } [Reactive] private string _email; [Reactive] private string _username; [Reactive] private string _password; public RegisterPageViewModel(IScreen hostScreen) { HostScreen = hostScreen; } [ReactiveCommand] private async Task RegisterAsync() { try { await Api.C.Gateway.Register(new RegisterRequest { Email = _email, Username = _username, Password = _password }); await Api.C.LoginAsync(Username, Password); } catch (ApiException ex) { await Console.Error.WriteLineAsync($"Register as '{Username}' Failed: {ex.Content}"); UIHelper.NotifyError(ex); } catch (Exception ex) { await Console.Error.WriteLineAsync($"Register as '{Username}' Failed: {ex}"); UIHelper.NotifyError(ex); } Console.WriteLine($"Register as '{Username}' success!"); } }