Exemplo n.º 1
0
        public async Task <List <OwnedAccountModel> > GetAllCloudAccounts(List <string> userIdList)
        {
            const string queryTemplate =
                "Select Id, AccountName, AccountType, CreatorUserID from CloudAccounts where CreatorUserID in ({0})";
            var queryParameter = string.Join(',', userIdList.Select(x => $"'{x}'"));
            var query          = string.Format(queryTemplate, queryParameter);

            await using var command = _connection.CreateCommand();
            command.CommandType     = CommandType.Text;
            command.CommandText     = query;
            if (_connection.State != ConnectionState.Open)
            {
                await _connection.OpenAsync();
            }

            var result = new List <OwnedAccountModel>();

            await using var reader = await command.ExecuteReaderAsync(CommandBehavior.CloseConnection);

            while (await reader.ReadAsync())
            {
                var record = new OwnedAccountModel
                {
                    Id            = await reader.GetFieldValueAsync <long>("Id"),
                    AccountName   = await reader.GetFieldValueAsync <string>("AccountName"),
                    AccountType   = await reader.GetFieldValueAsync <int>("AccountType"),
                    CreatorUserId = await reader.GetFieldValueAsync <string>("CreatorUserID")
                };
                result.Add(record);
            }

            return(result);
        }
Exemplo n.º 2
0
        public async Task <OwnedAccountModel> GetAccountById(long accountId)
        {
            await using var command = _connection.CreateCommand();
            command.CommandType     = CommandType.StoredProcedure;
            command.CommandText     = "GetAccountById";
            command.Parameters.AddWithValue("@Id", accountId);

            if (_connection.State != ConnectionState.Open)
            {
                await _connection.OpenAsync();
            }
            await using var reader = await command.ExecuteReaderAsync(CommandBehavior.CloseConnection);

            if (await reader.ReadAsync())
            {
                var record = new OwnedAccountModel
                {
                    Id            = await reader.GetFieldValueAsync <long>("Id"),
                    AccountName   = await reader.GetFieldValueAsync <string>("AccountName"),
                    AccountType   = await reader.GetFieldValueAsync <int>("AccountType"),
                    CreatorUserId = await reader.GetFieldValueAsync <string>("CreatorUserID")
                };
                return(record);
            }

            return(null);
        }