mekasu0124

Untitled

Mar 9th, 2024
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using SeedDb.Services;
  2. using ReactiveUI;
  3. using System.Reactive;
  4. using SeedDb.Models;
  5. using System;
  6.  
  7. namespace SeedDb.ViewModels;
  8.  
  9. public class TermsOfServiceViewModel : ViewModelBase
  10. {
  11.     private JsonEngine _js = new();
  12.     private Helpers _hp = new();
  13.  
  14.     private string _title = "";
  15.     private string _info = "";
  16.  
  17.     public TermsOfServiceViewModel(JsonEngine js, Helpers hp)
  18.     {
  19.         _js = js;
  20.         _hp = hp;
  21.     }
  22.  
  23.     public TermsOfServiceViewModel()
  24.     {
  25.         Title = "Terms Of Service";
  26.         Info = Hp.GetTosText();
  27.  
  28.         IObservable<bool> okEnabled = this.WhenAnyValue(
  29.             x => x.Info,
  30.             x => !string.IsNullOrEmpty(x));
  31.  
  32.         Ok = ReactiveCommand.Create(ReturnAgreedTos, okEnabled);
  33.         Cancel = ReactiveCommand.Create(ReturnDeclinedTos, okEnabled);
  34.     }
  35.  
  36.     public SetupModel ReturnAgreedTos()
  37.     {
  38.         return new SetupModel()
  39.         {
  40.             Setup = false,
  41.             Tos = Js.UpdateTos()
  42.         };
  43.     }
  44.  
  45.     public SetupModel ReturnDeclinedTos()
  46.     {
  47.         return new SetupModel()
  48.         {
  49.             Setup = false,
  50.             Tos = false
  51.         };
  52.     }
  53.  
  54.     public ReactiveCommand<Unit, SetupModel> Ok { get; } = default!;
  55.     public ReactiveCommand<Unit, SetupModel> Cancel { get; } = default!;
  56.  
  57.     public JsonEngine Js
  58.     {
  59.         get => _js;
  60.         set => this.RaiseAndSetIfChanged(ref _js, value);
  61.     }
  62.  
  63.     public Helpers Hp
  64.     {
  65.         get => _hp;
  66.         set => this.RaiseAndSetIfChanged(ref _hp, value);
  67.     }
  68.  
  69.     public string Title
  70.     {
  71.         get => _title;
  72.         set => this.RaiseAndSetIfChanged(ref _title, value);
  73.     }
  74.  
  75.     public string Info
  76.     {
  77.         get => _info;
  78.         set => this.RaiseAndSetIfChanged(ref _info, value);
  79.     }
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment