tycg_carviolation_BE/Traffic.Repository/Implements/TycgRepository.cs

65 lines
2.3 KiB
C#

using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traffic.Data.Models;
using Traffic.Repository.Interfaces;
namespace Traffic.Repository.Implements
{
public class TycgRepository : ITycgRepository
{
public IDbTransaction Transaction { get; }
public IDbConnection Connection => Transaction.Connection;
public TycgRepository(IDbTransaction transaction)
{
Transaction = transaction;
}
public IEnumerable<Tycg> GetTycgs(string tableName)
{
var sql = string.Empty;
switch (tableName.ToLower().Trim())
{
case "tycg_logases":
sql = $"SELECT * FROM tycg_logases order by timestamp desc";
break;
case "tycg_logbigcarviolation":
sql = $"SELECT * FROM tycg_logbigcarviolation order by timestamp desc";
break;
case "tycg_logchecked":
sql = $"SELECT * FROM tycg_logchecked order by timestamp desc";
break;
case "tycg_logcrossroad":
sql = $"SELECT * FROM tycg_logcrossroad order by timestamp desc";
break;
case "tycg_logmalfunctionhttp":
sql = $"SELECT * FROM tycg_logmalfunctionhttp order by timestamp desc";
break;
case "tycg_logrejected":
sql = $"SELECT * FROM tycg_logrejected order by timestamp desc";
break;
case "tycg_logtraffichttp":
sql = $"SELECT * FROM tycg_logtraffichttp order by timestamp desc";
break;
case "tycg_loguploaded":
sql = $"SELECT * FROM tycg_loguploaded order by timestamp desc";
break;
default:
break;
}
return Connection.Query<Tycg>(sql, null, Transaction);
}
public IEnumerable<Log_Mapping> GetTycgsTableName()
{
var sql = $"SELECT * FROM {nameof(Log_Mapping)}";
return Connection.Query<Log_Mapping>(sql, null, Transaction);
}
}
}