68 lines
2.6 KiB
C#
68 lines
2.6 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 NotPunishRepository : INotPunishRepository
|
|||
|
{
|
|||
|
public IDbTransaction Transaction { get; }
|
|||
|
public IDbConnection Connection => Transaction.Connection;
|
|||
|
|
|||
|
public NotPunishRepository(IDbTransaction transaction)
|
|||
|
{
|
|||
|
Transaction = transaction;
|
|||
|
}
|
|||
|
|
|||
|
public IEnumerable<NotPunish> GetNotPunishs()
|
|||
|
{
|
|||
|
var sql = $"SELECT * FROM {nameof(NotPunish)}";
|
|||
|
return Connection.Query<NotPunish>(sql, null, Transaction);
|
|||
|
}
|
|||
|
|
|||
|
public NotPunish GetNotPunishById(int id)
|
|||
|
{
|
|||
|
var sql = $"SELECT * FROM {nameof(NotPunish)} Where {nameof(NotPunish.Id)} = @{nameof(NotPunish.Id)}";
|
|||
|
return Connection.QueryFirstOrDefault<NotPunish>(sql, new { id }, Transaction);
|
|||
|
}
|
|||
|
|
|||
|
public bool InsertNotPunish(NotPunish data)
|
|||
|
{
|
|||
|
var sql = $@"INSERT INTO {nameof(NotPunish)} (
|
|||
|
{nameof(NotPunish.EventTypeId)},
|
|||
|
{nameof(NotPunish.NotPunishType)},
|
|||
|
{nameof(NotPunish.NotPunishReason)})
|
|||
|
VALUES(@{nameof(NotPunish.EventTypeId)},
|
|||
|
@{nameof(NotPunish.NotPunishType)},
|
|||
|
@{nameof(NotPunish.NotPunishReason)})";
|
|||
|
|
|||
|
var result = Connection.Execute(sql, data, Transaction);
|
|||
|
return result == 1;
|
|||
|
}
|
|||
|
|
|||
|
public bool UpdateNotPunish(NotPunish data)
|
|||
|
{
|
|||
|
var sql = $@"UPDATE {nameof(NotPunish)}
|
|||
|
SET {nameof(NotPunish.EventTypeId)} = @{nameof(NotPunish.EventTypeId)},
|
|||
|
{nameof(NotPunish.NotPunishType)} = @{nameof(NotPunish.NotPunishType)},
|
|||
|
{nameof(NotPunish.NotPunishReason)} = @{nameof(NotPunish.NotPunishReason)}
|
|||
|
WHERE {nameof(NotPunish.Id)} = @{nameof(NotPunish.Id)}";
|
|||
|
var result = Connection.Execute(sql, data, Transaction);
|
|||
|
return result == 1;
|
|||
|
}
|
|||
|
|
|||
|
public bool DeleteNotPunish(int id)
|
|||
|
{
|
|||
|
var sql = $@"DELETE FROM {nameof(NotPunish)} WHERE {nameof(NotPunish.Id)} = @{nameof(NotPunish.Id)}";
|
|||
|
var result = Connection.Execute(sql, new { id }, Transaction);
|
|||
|
return result == 1;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|