0% found this document useful (0 votes)
81 views2 pages

DButil

This document defines a DButils class that implements an IDBUtil interface. The DButils class is used to access a database based on connection string configuration to retrieve records. It constructs using options for client configuration, injected configuration, and http context. The GetRecords method opens a SQL connection, executes a command asynchronously, and reads records into a list while looping through the returned reader.

Uploaded by

Subhash S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views2 pages

DButil

This document defines a DButils class that implements an IDBUtil interface. The DButils class is used to access a database based on connection string configuration to retrieve records. It constructs using options for client configuration, injected configuration, and http context. The GetRecords method opens a SQL connection, executes a command asynchronously, and reads records into a list while looping through the returned reader.

Uploaded by

Subhash S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

using Microsoft.AspNetCore.

Http;

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Security.Claims;
using System.Threading.Tasks;
using subhash.Model;

namespace subhash.Data
{
public class DButils : IDBUtil
{

private readonly string connectionString;


private readonly IOptions<ClientConnSettingsContainer> _clientConfig;
private readonly IHttpContextAccessor _context;

public DButils(IOptions<ClientConnSettingsContainer> clientConfig,


IConfiguration configuration,
IHttpContextAccessor context)
{

_clientConfig = clientConfig;
_context = context;
connectionString = configuration.GetConnectionString("");

public async Task<List<CustomerAllocationModel>> GetRecords()


{
using (SqlConnection cnn = new SqlConnection(connectionString))
{
string sql = " ";
using (SqlCommand cmd = new SqlCommand(sql, cnn))
{
cnn.Open();
using (var rdr = await cmd.ExecuteReaderAsync())
{

while(await rdr.ReadAsync())
{

return customerAllocation;

}
}
}

public interface IDBUtil


{
Task<List<CustomerAllocationModel>> GetRecords();
}

You might also like