Actually I'm working using dapper.
LoginAuditModel:
public class LoginAuditModel
{
public IList<GuidIdTableType> UserIdTableType { get; set; } = new List<GuidIdTableType>();
public DateTime StartingDate { get; set; }
public DateTime EndingDate { get; set; }
}
Repository:
public async Task<IEnumerable<LoginAuditGetViewModel>> LoginAuditGet(LoginAuditModel model)
{
try
{
async Task<IEnumerable<LoginAuditGetViewModel>> DoLoginAuditGet()
{
using (var connection = _connectionManager.GetOpenConnection(_configuration.GetConnectionString(connectionstring)))
{
return await connection.QueryAsync<LoginAuditGetViewModel>("[dbo].[spName]", param: new
{
UserIdTableType = ((List<GuidIdTableType>)model.UserIdTableType).ToDataTable(),
model.StartingDate,
model.EndingDate
}
, commandType: CommandType.StoredProcedure);
}
}
return await DoLoginAuditGet();
}
catch (Exception ex)
{
throw ex;
}
}
Service:
public async Task<IEnumerable<LoginAuditGetViewModel>> LoginAuditGet(LoginAuditModel model)
{
async Task<IEnumerable<LoginAuditGetViewModel>> DoLoginAuditGet()
{
return await _employeeRepository.LoginAuditGet(model);
}
return await DoLoginAuditGet();
}
Controller:
[HttpGet]
public async Task<IActionResult> LoginAuditGet([FromQuery]LoginAuditModel model)
{
try
{
async Task<IActionResult> DoLoginAuditGet()
{
var rModel = await _employeeService.LoginAuditGet(model);
if (rModel is null || !rModel.Any()) return NotFound();
return Ok(rModel);
}
return await DoLoginAuditGet();
}
catch (Exception ex)
{
return InternalServerError(ex);
}
}
When I execute this code using swagger in my case, table valued parameter is always passing with count = 0 (UserIdTableType), but for some reason, when I change controller method to [HttpPost] it pass parameter correctly! and everything it's working fine:
[HttpPost]
public async Task<IActionResult> LoginAuditGet(LoginAuditModel model)
{
try
{
async Task<IActionResult> DoLoginAuditGet()
{
var rModel = await _employeeService.LoginAuditGet(model);
if (rModel is null || !rModel.Any()) return NotFound();
return Ok(rModel);
}
return await DoLoginAuditGet();
}
catch (Exception ex)
{
return InternalServerError(ex);
}
}
So, my question is why it is working as a Post method and not with Get? I need to change something to works with Get? Regards