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, INoticeScheduleRepository { public NoticeScheduleRepository(IDatabaseHelper databaseHelper) : base(databaseHelper) { tableName = "notice_schedule"; } public async Task> GetNotYetDelivery() { List result; using (IDbConnection conn = this._databaseHelper.GetConnection()) { try { var sql = $"SELECT * FROM {tableName} WHERE IsDelivery = 0"; result = (await conn.QueryAsync(sql)).ToList(); } catch (Exception exception) { throw exception; } return result; } } public async Task UpdateList(List noticeSchedules, List 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(); } } } } } }