using Microsoft.Data.SqlClient;
using Dapper;
namespace PhotoTkutimes.Models
{
    public class DtlPageData
    {
        public List<DtlNews> dtlNews { get; set; }
        public List<DtlImg> dtlImg { get; set; }
        public List<NewsDataLink> dtlPrev { get; set; }
        public List<NewsDataLink> dtlNext { get; set; }
        public List<DtlFile> dtlFiles { get; set; }

        public List<DtlSdgs> dtlSdgs { get; set; }

        public static DtlPageData getDtlPageData(IConfiguration configuration, int no, string l)
        {
            DtlPageData dtlPageDatas = new DtlPageData();

            string connstr = configuration.GetConnectionString("TKUTIMES");

            using (var connection = new SqlConnection(connstr))
            {
                try
                {
                    var values = new
                    {
                        Seqno = no
                        ,
                        langtype = l
                    };
                    var sql = "tkutimesGetDtlNewsV2016";
                    var result = connection.QueryMultiple(sql, values, commandType: System.Data.CommandType.StoredProcedure);
                    dtlPageDatas.dtlNews = result.Read<DtlNews>().ToList();
                    dtlPageDatas.dtlImg = result.Read<DtlImg>().ToList();
                    dtlPageDatas.dtlPrev = result.Read<NewsDataLink>().ToList();
                    dtlPageDatas.dtlNext = result.Read<NewsDataLink>().ToList();
                    dtlPageDatas.dtlFiles = result.Read<DtlFile>().ToList();
                    dtlPageDatas.dtlSdgs = result.Read<DtlSdgs>().ToList();
                }
                catch (Exception e)
                {
                    return null;
                }
            }
            return dtlPageDatas;
        }
    }
}
