99 lines
3.1 KiB
C#
99 lines
3.1 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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public async Task<List<OperationPersonnel>> GetPowerStationOperationPersonnel(int Userid)
|
|
{
|
|
using (IDbConnection conn = this._databaseHelper.GetConnection())
|
|
{
|
|
conn.Open();
|
|
var result = new List<OperationPersonnel>();
|
|
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<OperationPersonnel>(sql)).ToList();
|
|
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
trans.Rollback();
|
|
throw exception;
|
|
}
|
|
finally
|
|
{
|
|
conn.Close();
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|