ApplicationSettings.cs 1.83 KB
using MongoDB.Bson;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Configuration;

namespace AIAHTML5.Server.Models
{
    public class ApplicationSettings
    {
        public static dynamic GetApplicationSettings(string applicationName, string userId = null)
        {
            try
            {
                var client = new MongoClient();
                var db = client.GetDatabase(ConfigurationManager.AppSettings["database"]);

                var col = db.GetCollection<dynamic>("app-settings");

                dynamic appSettings = col.Find(Builders<dynamic>.Filter.Eq("app", applicationName)).Limit(1).SingleOrDefault();

                //if (userId != null)
                //{
                //    var colUser = db.GetCollection<dynamic>("users");

                //    dynamic user = colUser.Find(Builders<dynamic>.Filter.Eq("_id", ObjectId.Parse(userId))).SingleOrDefault();
                    
                //    if (user != null)
                //    {
                //        string role = user.role.ToString();

                //        for (int i = 0; i < appSettings.menu.menuItems.Count; i++)
                //        {
                //            //List<dynamic> menuItems = new List<dynamic>();
                //            for (int j = 0; j < appSettings.menu.menuItems[i].roles.Count; j++)
                //            {
                //                if (appSettings.menu.menuItems[i].roles[j].ToString() == role)
                //                {
                                    
                //                }
                //            }
                //        }
                //    }
                //}

                return appSettings;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
    }
}