FIC_Solar/SolarPower/Repository/Implement/OperatorLogRepository.cs
2021-06-09 15:03:24 +08:00

50 lines
1.4 KiB
C#

using Dapper;
using SolarPower.Helper;
using SolarPower.Models.OperatorLogModel;
using SolarPower.Repository.Interface;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
namespace SolarPower.Repository.Implement
{
public class OperatorLogRepository : RepositoryBase<OperatorLog>, IOperatorLogRepository
{
public OperatorLogRepository(IDatabaseHelper databaseHelper) : base(databaseHelper)
{
tableName = "operator_log";
}
public void Add(OperatorLog entity, List<string> properties)
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
var sql = GenerateInsertQuery(properties);
conn.Execute(sql, entity, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
}
}
}
}