diff --git a/QRBee.Core/ClientCardData.cs b/QRBee.Core/Data/ClientCardData.cs similarity index 97% rename from QRBee.Core/ClientCardData.cs rename to QRBee.Core/Data/ClientCardData.cs index 37a7a7d..4ac2dd7 100644 --- a/QRBee.Core/ClientCardData.cs +++ b/QRBee.Core/Data/ClientCardData.cs @@ -1,4 +1,4 @@ -namespace QRBee.Core +namespace QRBee.Core.Data { public class ClientCardData { diff --git a/QRBee/QRBee.Android/Services/LocalSettings.cs b/QRBee/QRBee.Android/Services/LocalSettings.cs index 4cc3088..2007351 100644 --- a/QRBee/QRBee.Android/Services/LocalSettings.cs +++ b/QRBee/QRBee.Android/Services/LocalSettings.cs @@ -18,14 +18,15 @@ namespace QRBee.Droid.Services await Application.Current.SavePropertiesAsync(); } - public Task LoadSettings() + public Settings LoadSettings() { if (!Application.Current.Properties.ContainsKey("Settings")) - return Task.FromResult(new Settings()); + return new Settings(); var json = Application.Current.Properties["Settings"].ToString(); var settings = JsonConvert.DeserializeObject(json); - return Task.FromResult(settings); + + return settings; } } } \ No newline at end of file diff --git a/QRBee/QRBee/Services/ILocalSettings.cs b/QRBee/QRBee/Services/ILocalSettings.cs index 5f3cbaf..46dffb6 100644 --- a/QRBee/QRBee/Services/ILocalSettings.cs +++ b/QRBee/QRBee/Services/ILocalSettings.cs @@ -26,7 +26,7 @@ namespace QRBee.Services { string QRBeeApiUrl { get; } Task SaveSettings(Settings settings); - Task LoadSettings(); + Settings LoadSettings(); } diff --git a/QRBee/QRBee/ViewModels/ClientPageViewModel.cs b/QRBee/QRBee/ViewModels/ClientPageViewModel.cs index 6959093..fe8bc09 100644 --- a/QRBee/QRBee/ViewModels/ClientPageViewModel.cs +++ b/QRBee/QRBee/ViewModels/ClientPageViewModel.cs @@ -44,9 +44,9 @@ namespace QRBee.ViewModels IsVisible = true; } } - catch (Exception ex) + catch (Exception) { - throw; + await Application.Current.MainPage.DisplayAlert("Error","Wrong QR code scanned","Ok"); } } diff --git a/QRBee/QRBee/ViewModels/LoginViewModel.cs b/QRBee/QRBee/ViewModels/LoginViewModel.cs index b6f084d..99f52b7 100644 --- a/QRBee/QRBee/ViewModels/LoginViewModel.cs +++ b/QRBee/QRBee/ViewModels/LoginViewModel.cs @@ -38,7 +38,7 @@ namespace QRBee.ViewModels //Insert PIN IsPinVisible = true; var localSettings = DependencyService.Resolve(); - var pin = (await localSettings.LoadSettings()).PIN; + var pin = localSettings.LoadSettings().PIN; if (!string.IsNullOrEmpty(pin) && pin.Equals(PinCode)) { diff --git a/QRBee/QRBee/ViewModels/MerchantPageViewModel.cs b/QRBee/QRBee/ViewModels/MerchantPageViewModel.cs index 0dadfaf..47942b5 100644 --- a/QRBee/QRBee/ViewModels/MerchantPageViewModel.cs +++ b/QRBee/QRBee/ViewModels/MerchantPageViewModel.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using QRBee.Core.Data; using QRBee.Services; using Xamarin.Forms; @@ -8,7 +9,6 @@ namespace QRBee.ViewModels internal class MerchantPageViewModel : BaseViewModel { private bool _isVisible; - private string _name; private decimal _amount; private string _qrCode; @@ -19,6 +19,8 @@ namespace QRBee.ViewModels { ScanCommand = new Command(OnScanButtonClicked); GenerateQrCommand = new Command(OnGenerateQrClicked); + var localSettings = DependencyService.Resolve(); + Name = localSettings.LoadSettings().Name; } private async void OnScanButtonClicked(object sender) @@ -38,17 +40,7 @@ namespace QRBee.ViewModels } } - public string Name - { - get => _name; - set - { - if (_name == value) - return; - _name = value; - OnPropertyChanged(nameof(Name)); - } - } + public string Name { get; } public decimal Amount { @@ -98,16 +90,24 @@ namespace QRBee.ViewModels /// public async void OnGenerateQrClicked(object obj) { - var trans = new MerchantToClientRequest + if (string.IsNullOrWhiteSpace(Name) || Amount==0) { - TransactionId = Guid.NewGuid().ToString("D"), - Name = Name, - Amount = Amount, - TimeStampUTC = DateTime.UtcNow - }; - // TODO Create merchant signature. - QrCode = trans.AsString(); - IsVisible = true; + await Application.Current.MainPage.DisplayAlert("Error", "The fields must be filled", "Ok"); + } + else + { + var trans = new MerchantToClientRequest + { + TransactionId = Guid.NewGuid().ToString("D"), + Name = Name, + Amount = Amount, + TimeStampUTC = DateTime.UtcNow + }; + // TODO Create merchant signature. + QrCode = trans.AsString(); + IsVisible = true; + } + } } diff --git a/QRBee/QRBee/ViewModels/RegisterViewModel.cs b/QRBee/QRBee/ViewModels/RegisterViewModel.cs index a6c9568..ba9bea1 100644 --- a/QRBee/QRBee/ViewModels/RegisterViewModel.cs +++ b/QRBee/QRBee/ViewModels/RegisterViewModel.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Net.Http; using QRBee.Core; +using QRBee.Core.Data; using QRBee.Services; using QRBee.Views; using Xamarin.Forms; @@ -75,6 +76,24 @@ namespace QRBee.ViewModels try { + + //save local settings + var settings = new Settings + { + CardHolderName = CardHolderName, + CardNumber = CardNumber, + CVC = CVC, + DateOfBirth = DateOfBirth, + Email = Email, + ExpirationDate = ExpirationDate, + IsRegistered = true, + IssueNo = IssueNo, + ValidFrom = ValidFrom, + Name = Name, + PIN = Pin + }; + await localSettings.SaveSettings(settings); + await service.RegisterAsync(new RegistrationRequest { DateOfBirth = DateOfBirth, @@ -83,23 +102,6 @@ namespace QRBee.ViewModels RegisterAsMerchant = false }); - //save local settings - var settings = new Settings - { - CardHolderName = CardHolderName, - CardNumber = CardNumber, - CVC = CVC, - DateOfBirth = DateOfBirth, - Email = Email, - ExpirationDate = ExpirationDate, - IsRegistered = true, - IssueNo = IssueNo, - ValidFrom = ValidFrom, - Name = Name, - PIN = Pin - }; - await localSettings.SaveSettings(settings); - await Shell.Current.GoToAsync($"//{nameof(MainPage)}"); } catch (Exception) diff --git a/QRBee/QRBee/Views/MerchantPage.xaml b/QRBee/QRBee/Views/MerchantPage.xaml index 3ba6def..3083f91 100644 --- a/QRBee/QRBee/Views/MerchantPage.xaml +++ b/QRBee/QRBee/Views/MerchantPage.xaml @@ -12,8 +12,7 @@ -