FIC_Solar/SolarPower/Repository/Implement/NoticeScheduleRepository.cs
Kai 69007218b5 1. bug fix
2. 加入寄信背景服務
2021-08-02 13:47:15 +08:00

69 lines
2.0 KiB
C#

using Dapper;
using SolarPower.Helper;
using SolarPower.Models;
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 NoticeScheduleRepository : RepositoryBase<NoticeSchedule>, INoticeScheduleRepository
{
public NoticeScheduleRepository(IDatabaseHelper databaseHelper) : base(databaseHelper)
{
tableName = "notice_schedule";
}
public async Task<List<NoticeSchedule>> GetNotYetDelivery()
{
List<NoticeSchedule> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
{
var sql = $"SELECT * FROM {tableName} WHERE IsDelivery = 0";
result = (await conn.QueryAsync<NoticeSchedule>(sql)).ToList();
}
catch (Exception exception)
{
throw exception;
}
return result;
}
}
public async Task UpdateList(List<NoticeSchedule> noticeSchedules, List<string> properties)
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
var sql = GenerateUpdateQuery(properties);
await conn.ExecuteAsync(sql, noticeSchedules, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
}
}
}
}