public static bool toDTO(DBExpertcluster cluster, ref ExpertsCluster result)
        {
            try
            {
                result.Id      = cluster.Id;
                result.Name    = cluster.Name;
                result.Retired = cluster.Retired;
                if (cluster.Typ != null)
                {
                    result.Typ = cluster.Typ.Value;
                }
                if (cluster.Metasymbol != null)
                {
                    result.MetaSymbol   = cluster.Metasymbol.Name;
                    result.MetaSymbolId = cluster.Metasymbol.Id;
                }

                if (cluster.Adviser != null)
                {
                    result.MasterAdviserId = cluster.Adviser.Id;
                }

                result.Advisers = new List <Adviser>();
                return(true);
            } catch
            {
                return(false);
            }
        }
        /*
         * public void MigrateAdvisersData()
         * {
         *  var ds = MainService.thisGlobal.Container.Resolve<DataService>();
         *
         *  // List<Adviser> results = new List<Adviser>();
         *  using (ISession Session = ConnectionHelper.CreateNewSession())
         *  {
         *      var advisers = Session.Query<DBAdviser>();
         *      foreach (var dbadv in advisers)
         *      {
         *          //Adviser adv = new Adviser();
         *          //if (toDTO(dbadv, ref adv))
         *          //    results.Add(adv);
         *          try
         *          {
         *              if (String.IsNullOrEmpty(dbadv.State))
         *                  continue;
         *              Dictionary<string, object> res = JsonConvert.DeserializeObject<Dictionary<string, object>>(dbadv.State);
         *
         *              Dictionary<string, TDynamicProperty<object> > result = new Dictionary<string, TDynamicProperty<object> >();
         *              foreach(var prop in res)
         *              {
         *                  TDynamicProperty<object> p = new TDynamicProperty<object>();
         *                  if (prop.Value != null)
         *                  {
         *                      p.type = prop.Value.GetType().ToString();
         *                      switch (p.type)
         *                      {
         *                          case "System.Int64":
         *                              p.type = "integer";
         *                              break;
         *                          case "System.Double":
         *                              p.type = "double";
         *                              break;
         *                          case "System.Boolean":
         *                              p.type = "boolean";
         *                              break;
         *                          default:
         *                              p.type = "string";
         *                              break;
         *                      }
         *
         *                  }
         *                  else p.type = "string";
         *                  if (prop.Key.Equals("InfoTextColor"))
         *                      p.type = "hexinteger";
         *
         *                  p.value = prop.Value;
         *                  result.Add(prop.Key, p);
         *              }
         *
         *              DynamicProperties dp = new DynamicProperties();
         *              dp.entityType = (short)EntitiesEnum.Adviser;
         *              dp.objId = dbadv.Id;
         *              dp.updated = DateTime.UtcNow;
         *              dp.Vals = JsonConvert.SerializeObject(result);
         *              ds.SavePropertiesInstance(dp);
         *
         *          } catch (Exception e)
         *          {
         *              log.Info("Failed to migrate: Adviser: " + dbadv.Id.ToString() + ", " + e.ToString());
         *          }
         *      }
         *  }
         * }*/

        public List <ExpertsCluster> GetClusters()
        {
            List <ExpertsCluster> results = new List <ExpertsCluster>();

            using (ISession Session = ConnectionHelper.CreateNewSession())
            {
                var clusters = Session.Query <DBExpertcluster>();
                foreach (var dbCluster in clusters)
                {
                    ExpertsCluster cluster = new ExpertsCluster();
                    if (toDTO(dbCluster, ref cluster))
                    {
                        var advisers = Session.Query <DBAdviser>()
                                       .Where(x => x.Cluster != null && x.Cluster.Id == cluster.Id);
                        foreach (var dbAdviser in advisers)
                        {
                            Adviser adv = new Adviser();
                            if (toDTO(dbAdviser, ref adv))
                            {
                                cluster.Advisers.Add(adv);
                            }
                        }
                        results.Add(cluster);
                    }
                }
            }

            return(results);
        }