using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;
using System.ComponentModel;

namespace digioz
{
    public class PortalMetadataManagement
    {
        private static PortalSettings coPortalSettings;

        public static PortalMetadata GetPortalMetadata()
        {
            PortalMetadata loPortalMetadata = new PortalMetadata();
            coPortalSettings = PortalSettingsManagement.GetPortalSettings();

            if (coPortalSettings.DBRelational == true)
            {
                IDataRelational loDB = DataFactory.GetDataObject(coPortalSettings);
                DataTable loPortalMetadataTable;

                string lsSQL = "SELECT TOP 1* FROM tblPortalMetadata ORDER BY portalmetadata_id DESC;";

                loDB.openConnection();
                loPortalMetadataTable = loDB.QueryDBDataset(lsSQL);
                loDB.closeConnection();
                DataRow loDR = loPortalMetadataTable.Rows[0];

                loPortalMetadata = new PortalMetadata();
                loPortalMetadata.ID = Convert.ToInt16(loDR["portalmetadata_id"]);
                loPortalMetadata.Keywords = Convert.ToString(loDR["portalmetadata_keywords"]);
                loPortalMetadata.Description = Convert.ToString(loDR["portalmetadata_description"]);
                loPortalMetadata.PageName = Convert.ToString(loDR["portalmetadata_page"]);
            }
            else
            {
                // Non Relational Database
            }
            return loPortalMetadata;
        }

        public static bool SavePortalMetadata(PortalMetadata poPortalMetadata)
        {
            coPortalSettings = PortalSettingsManagement.GetPortalSettings();
            bool lbResult = false;

            if (coPortalSettings.DBRelational == true)
            {
                IDataRelational loDB = DataFactory.GetDataObject(coPortalSettings);
                string lsSQL = String.Empty;

                lsSQL = "EXEC spUpdatePortalMetadata "
                        + "@id = " + poPortalMetadata.ID + ","
                        + "@keywords = '" + poPortalMetadata.Keywords + "',"
                        + "@description = '" + poPortalMetadata.Description + "';";

                loDB.openConnection();
                loDB.ExecDB(lsSQL);
                loDB.closeConnection();
                lbResult = String.IsNullOrEmpty(loDB.sErr);
            }
            else
            {
                // Non Relational Database
            }
            return lbResult;
        }
    }
}