public async Task <ActionResult <IEnumerable <Account> > > Get( AccountTypeParameter type, ContractKindParameter kind, SelectParameter select, SortParameter sort, OffsetParameter offset, [Range(0, 10000)] int limit = 100) { #region validate if (sort != null && !sort.Validate("id", "balance", "firstActivity", "lastActivity", "numTransactions", "numContracts")) { return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed.")); } #endregion #region optimize if (kind?.Eq != null && type == null) { type = new AccountTypeParameter { Eq = 2 } } ; #endregion if (select == null) { return(Ok(await Accounts.Get(type, kind, sort, offset, limit))); } if (select.Values != null) { if (select.Values.Length == 1) { return(Ok(await Accounts.Get(type, kind, sort, offset, limit, select.Values[0]))); } else { return(Ok(await Accounts.Get(type, kind, sort, offset, limit, select.Values))); } } else { if (select.Fields.Length == 1) { return(Ok(await Accounts.Get(type, kind, sort, offset, limit, select.Fields[0]))); } else { return(Ok(new SelectionResponse { Cols = select.Fields, Rows = await Accounts.Get(type, kind, sort, offset, limit, select.Fields) })); } } }
public Task <int> GetCount(AccountTypeParameter type, ContractKindParameter kind) { #region optimize if (type == null && kind == null) { return(Task.FromResult(State.GetState().AccountsCount)); } if (kind?.Eq != null && type == null) { type = new AccountTypeParameter { Eq = 2 } } ; #endregion return(Accounts.GetCount(type, kind)); }
public Task <int> GetCount( AccountTypeParameter type, ContractKindParameter kind, Int64Parameter balance, BoolParameter staked) { #region optimize if (type == null && kind == null && balance == null && staked == null) { return(Task.FromResult(State.Current.AccountsCount)); } if (kind?.Eq != null && type == null) { type = new AccountTypeParameter { Eq = 2 } } ; #endregion return(Accounts.GetCount(type, kind, balance, staked)); }
public async Task <ActionResult <IEnumerable <Account> > > Get( AccountTypeParameter type, ContractKindParameter kind, AccountParameter @delegate, Int64Parameter balance, BoolParameter staked, Int32Parameter lastActivity, SelectParameter select, SortParameter sort, OffsetParameter offset, [Range(0, 10000)] int limit = 100) { #region validate if (@delegate != null) { if (@delegate.Eqx != null) { return(new BadRequest($"{nameof(@delegate)}.eqx", "This parameter doesn't support .eqx mode.")); } if (@delegate.Nex != null) { return(new BadRequest($"{nameof(@delegate)}.nex", "This parameter doesn't support .nex mode.")); } if (@delegate.Eq == -1 || @delegate.In?.Count == 0) { return(Ok(Enumerable.Empty <Account>())); } } if (sort != null && !sort.Validate("id", "balance", "firstActivity", "lastActivity", "numTransactions", "numContracts")) { return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed.")); } #endregion #region optimize if (kind?.Eq != null && type == null) { type = new AccountTypeParameter { Eq = 2 } } ; #endregion if (select == null) { return(Ok(await Accounts.Get(type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit))); } if (select.Values != null) { if (select.Values.Length == 1) { return(Ok(await Accounts.Get(type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Values[0]))); } else { return(Ok(await Accounts.Get(type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Values))); } } else { if (select.Fields.Length == 1) { return(Ok(await Accounts.Get(type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Fields[0]))); } else { return(Ok(new SelectionResponse { Cols = select.Fields, Rows = await Accounts.Get(type, kind, @delegate, balance, staked, lastActivity, sort, offset, limit, select.Fields) })); } } }
public async Task <ActionResult <IEnumerable <Contract> > > Get( ContractKindParameter kind, AccountParameter creator, AccountParameter manager, AccountParameter @delegate, Int32Parameter lastActivity, SelectParameter select, SortParameter sort, OffsetParameter offset, [Range(0, 10000)] int limit = 100, bool includeStorage = false) { #region validates if (creator != null) { if (creator.Eqx != null && creator.Eqx != "manager" && creator.Eqx != "delegate") { return(new BadRequest($"{nameof(creator)}.eqx", "The 'creator' field can be compared with the 'manager' or 'delegate' field only.")); } if (creator.Nex != null && creator.Nex != "manager" && creator.Nex != "delegate") { return(new BadRequest($"{nameof(creator)}.nex", "The 'creator' field can be compared with the 'manager' or 'delegate' field only.")); } if (creator.Eq == -1 || creator.In?.Count == 0) { return(Ok(Enumerable.Empty <Contract>())); } } if (manager != null) { if (manager.Eqx != null && manager.Eqx != "creator" && manager.Eqx != "delegate") { return(new BadRequest($"{nameof(manager)}.eqx", "The 'manager' field can be compared with the 'creator' or 'delegate' field only.")); } if (manager.Nex != null && manager.Nex != "creator" && manager.Nex != "delegate") { return(new BadRequest($"{nameof(manager)}.nex", "The 'manager' field can be compared with the 'creator' or 'delegate' field only.")); } if (manager.Eq == -1 || manager.In?.Count == 0) { return(Ok(Enumerable.Empty <Contract>())); } } if (@delegate != null) { if (@delegate.Eqx != null && @delegate.Eqx != "creator" && @delegate.Eqx != "manager") { return(new BadRequest($"{nameof(@delegate)}.eqx", "The 'delegate' field can be compared with the 'creator' or 'manager' field only.")); } if (@delegate.Nex != null && @delegate.Nex != "creator" && @delegate.Nex != "manager") { return(new BadRequest($"{nameof(@delegate)}.nex", "The 'delegate' field can be compared with the 'creator' or 'manager' field only.")); } if (@delegate.Eq == -1 || @delegate.In?.Count == 0) { return(Ok(Enumerable.Empty <Contract>())); } } if (sort != null && !sort.Validate("id", "balance", "firstActivity", "lastActivity", "numTransactions")) { return(new BadRequest($"{nameof(sort)}", "Sorting by the specified field is not allowed.")); } #endregion if (select == null) { return(Ok(await Accounts.GetContracts(kind, creator, manager, @delegate, lastActivity, sort, offset, limit, includeStorage))); } if (select.Values != null) { if (select.Values.Length == 1) { return(Ok(await Accounts.GetContracts(kind, creator, manager, @delegate, lastActivity, sort, offset, limit, select.Values[0], includeStorage))); } else { return(Ok(await Accounts.GetContracts(kind, creator, manager, @delegate, lastActivity, sort, offset, limit, select.Values, includeStorage))); } } else { if (select.Fields.Length == 1) { return(Ok(await Accounts.GetContracts(kind, creator, manager, @delegate, lastActivity, sort, offset, limit, select.Fields[0], includeStorage))); } else { return(Ok(new SelectionResponse { Cols = select.Fields, Rows = await Accounts.GetContracts(kind, creator, manager, @delegate, lastActivity, sort, offset, limit, select.Fields, includeStorage) })); } } }
public Task <int> GetCount(ContractKindParameter kind) { return(Accounts.GetContractsCount(kind)); }