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(); } } } } public async Task> GetPowerStationOperationPersonnel(int Userid) { using (IDbConnection conn = this._databaseHelper.GetConnection()) { conn.Open(); var result = new List(); using (var trans = conn.BeginTransaction()) { try { var sql = $@"SELECT p.*,ps.Name FROM power_station_operation_personnel p LEFT JOIN power_station ps ON p.PowerStationId = ps.Id WHERE p.UserId = {Userid} AND p.Deleted = 0 "; result = (await conn.QueryAsync(sql)).ToList(); } catch (Exception exception) { trans.Rollback(); throw exception; } finally { conn.Close(); } return result; } } } } }