using System;
using System.Collections.Generic;
using System.Data;
using System.Web;

namespace digioz
{
    public static class UserPermissionManagement
    {
        private static PortalSettings coPortalSettings;
        
        public static List<UserPermission> GetUserPermissions()
        {
            coPortalSettings = PortalSettingsManagement.GetPortalSettings();
            List<UserPermission> coResultList = new List<UserPermission>();

            if (coPortalSettings.DBRelational == true)
            {
                IDataRelational loDB = DataFactory.GetDataObject(coPortalSettings);
                DataTable loMenuItems;
                string lsSQL = "SELECT * FROM tblUserPermission";
                
                try
                {
                    loDB.openConnection();
                    loMenuItems = loDB.QueryDBDataset(lsSQL);

                    foreach (DataRow loDR in loMenuItems.Rows)
                    {
                        coResultList.Add(new UserPermission(
                            Convert.ToInt32(loDR[0]),
                            Convert.ToString(loDR[1]),
                            Convert.ToString(loDR[2])));
                    }
                }
                finally
                {
                    loDB.closeConnection();
                }
            }

            return coResultList;
        }
    }
}