Skip to content

Instantly share code, notes, and snippets.

@hendrasyp
Created April 5, 2023 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hendrasyp/0cb73166cba30171839b58495617eb6d to your computer and use it in GitHub Desktop.
Save hendrasyp/0cb73166cba30171839b58495617eb6d to your computer and use it in GitHub Desktop.
Asynchronous Api NET6
public async Task<IQueryable<object>> GetCountry()
{
MSSQLDataAccess helper = new MSSQLDataAccess(_options);
List<SqlParam> tParams = new List<SqlParam>();
tParams.Add(new SqlParam { ParamType = DataTypeConstant.STR, ParamValue = "" });
string strSQL = helper.BuildQueryString(TSqlHelper.spName("STOREDPROCEDURE"), tParams);
IQueryable<object> result = helper.Read(strSQL);
return await Task.FromResult(result);
}
public interface ICountryService
{
public Task<IQueryable<object>> GetCountry();
public Task<IQueryable<object>> GetCountryByName(string name);
public void Save(Basic_Master_Area_Country_Update data, string userId);
}
public async Task<IActionResult> GetCountry_List([FromQuery] Country_Get_Request country)
{
ResponseModels tResponse;
try
{
IQueryable<object> result;
if (CommonHelper.StringIsEmpty(country.name))
{
result = await _countryService.GetCountry();
}
else
{
result = await _countryService.GetCountryByName(country.name);
}
tResponse = _responseService.GenerateResponseMessage(RestStatus.OK.ToString(), result);
}
catch (SqlException ex)
{
tResponse = _responseService.GenerateResponseMessage(RestStatus.InternalServerError.ToString(), CommonHelper.GetGeneralException(ex));
}
catch (Exception ex)
{
tResponse = _responseService.GenerateResponseMessage(RestStatus.InternalServerError.ToString(), CommonHelper.GetGeneralException(ex));
}
return Ok(tResponse);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment