Created
September 27, 2017 18:08
-
-
Save Kikimora/c514a0c2c4fb51d7b362e07cef3ade77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Tab { Summary, Allocation, Transaction } | |
enum Range { All, YtD, MtD, D } | |
enum Role { RM, User } | |
class AssetManager {} | |
class Account {} | |
class OverviewModel | |
{ | |
struct FetchRequest | |
{ | |
public FetchRequest() | |
{ | |
Customer = null; | |
Range = Range.All; | |
Tab = Tab.Overview; | |
AssetManager = null; | |
Account = null; | |
} | |
Customer _customer; | |
public Customer Customer | |
{ | |
get => _customer; | |
set | |
{ | |
if (value != _customer) | |
{ | |
_customer = value; | |
AssetManager = null; | |
Account = null; | |
} | |
} | |
} | |
public Range Range; | |
public Tab Tab; | |
AssetManager _assetManager; | |
public AssetManager AssetManager | |
{ | |
get => _assetManager; | |
set | |
{ | |
if (value != _assetManager) | |
{ | |
if (_customer == null) throw new InvalidOperationException(); | |
_assetManager = value; | |
} | |
} | |
} | |
Account _account; | |
public Account Account | |
{ | |
get => _account; | |
set | |
{ | |
if (value != _account) | |
{ | |
if (AssetManager == null) throw new InvalidOperationException(); | |
_account = value; | |
} | |
} | |
} | |
} | |
struct FetchResult | |
{ | |
public AssetManager[] Managers; | |
public Account[] Accounts; | |
public decimal? TotalReturn; | |
public decimal? TotalValue; | |
public decimal? TotalTransactions; | |
} | |
FetchRequest _loaded; | |
FetchRequest _request; | |
FetchResult _data; | |
User _user; | |
public OverviewModel() | |
{ | |
LoadCommand = new AsyncCommand(Load) | |
{ | |
SerializationPolicy = AsyncCommandSerializationPolicy.Cancel | |
}; | |
} | |
public IAsyncCommand LoadCommand { get; } | |
private void Load(object arg, CancellationToken token) | |
{ | |
switch (arg) | |
{ | |
case Customer c: | |
_request.Customer = c; | |
break; | |
case AssetManager m: | |
_request.AssetManager = m; | |
break; | |
case Account a: | |
_request.Account = a; | |
break; | |
case Tab t: | |
_request.Tab = t; | |
break; | |
case Range r: | |
_request.Range = r; | |
break; | |
} | |
_data = await ProveoContext.SummaryService.Load(_request); | |
_loaded = _request; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment