Journeys_WantHome/Models/youtubeDetailClass.cs

64 lines
2.0 KiB
C#

using Dapper;
using Dapper.Contrib.Extensions;
using NPOI.SS.Formula.Functions;
using System.Data.SqlClient;
using System.Security.Cryptography.X509Certificates;
using static DbTableClass;
public class youtubeDetailClass : youtube
{
DbConn dbConn = new DbConn();
SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString"));
List<youtubeDetail> youtubeDetails = new List<youtubeDetail>();
private youtube _youtube;
public youtubeDetailClass()
{
_youtube = new youtube();
}
public youtubeDetailClass(youtube youtubeObj)
{
Type youtubeType = youtubeObj.GetType();
foreach (var prop in youtubeType.GetProperties())
{
string propName = prop.Name;
var valueProperty = youtubeType.GetProperty(propName);
object propValue = valueProperty.GetValue(youtubeObj, null);
this.GetType().GetProperty(propName).SetValue(this, propValue);
}
_youtube = youtubeObj;
loadList();
}
public youtubeDetailClass(string youtube_uid) {
_youtube = conn.QueryFirstOrDefault<youtube>("select * from youtube where youtube_uid = @youtube_uid", new { youtube_uid = youtube_uid });
if (_youtube != null)
{
youtube youtubeObj = _youtube;
Type youtubeType = youtubeObj.GetType();
foreach (var prop in youtubeType.GetProperties())
{
string propName = prop.Name;
var valueProperty = youtubeType.GetProperty(propName);
object propValue = valueProperty.GetValue(youtubeObj, null);
this.GetType().GetProperty(propName).SetValue(this, propValue);
}
loadList();
}
}
private void loadList()
{
youtubeDetails = conn.Query<youtubeDetail>("select * from youtubeDetail where youtube_uid = @youtube_uid", new { youtube_uid = _youtube.youtube_uid }).ToList();
}
}