//
        // GET: /Location/
        public ActionResult Index()
        {
            List<Location> wlocations = new List<Models.Location>();
            var mlocations = mdb.GetCollection("locations").FindAll();

            var collections = mdb.GetCollectionNames();
            foreach (var mlocation in mlocations)
            {
                Location wlocation = new Location();
                try { wlocation.ID = mlocation["_id"].ToString(); }
                catch (Exception) { };
                try { wlocation.name = mlocation["name"].ToString(); }
                catch (Exception) { };

                wlocations.Add(wlocation);
            }
            return View(wlocations);
        }
        private User mapMongoUser(BsonDocument muser, Dictionary<String, Object> profilesDic)
        {
            User wuser = new User();
                var muserID = muser["_id"].ToString();
                wuser.ID = muser["_id"].ToString();

                try
                {
                    var locations = muser["locations"].AsBsonArray.ToList();
                    wuser.LocationMIDs = new List<string>();
                    wuser.Locations = new List<Location>();
                    foreach (var mlocation in locations)
                    {

                        Location wlocation = new Location();
                        try { wlocation.ID = mlocation["_id"].ToString(); }
                        catch (Exception) { };
                        wuser.LocationMIDs.Add(wlocation.ID);
                        try { wlocation.name = mlocation["name"].ToString(); }
                        catch (Exception) { };
                        try { wlocation.description = mlocation["description"].ToString(); }
                        catch (Exception) { };

                        try { wlocation.lat = Convert.ToDouble(mlocation["latitude"].ToString()); }
                        catch (Exception) { };
                        try { wlocation.lon = Convert.ToDouble(mlocation["longitude"].ToString()); }
                        catch (Exception) { };

                        wuser.Locations.Add(wlocation);
                    }
                }
                catch (Exception) { };

                try
                {
                    var profileIDs = muser["profiles"].AsBsonArray.ToList();
                    wuser.ProfileMIDs = new List<string>();
                    wuser.Profiles = new List<Profile>();

                    int max = 10;
                    foreach (var profileID in profileIDs)
                    {
                        wuser.ProfileMIDs.Add(profileID.ToString());
                        dynamic mprofile;
                        profilesDic.TryGetValue(profileID.ToString(), out mprofile);
                        Profile wprofile = new Profile();
                        try { wprofile.ID = mprofile["_id"].ToString(); }
                        catch (Exception) { };
                        try { wprofile.name = mprofile["name"].ToString(); }
                        catch (Exception) { };
                        try { wprofile.Gender = mprofile["gender"].ToString(); }
                        catch (Exception) { };
                        try { wprofile.Age = Convert.ToInt16(mprofile["age"].ToString()); }
                        catch (Exception) { };

                        try
                        {
                            var conditions = mprofile["conditions"].AsBsonArray.ToList();
                            wprofile.ConditionIDs = new List<string>();
                            foreach (var condition in conditions) { wprofile.ConditionIDs.Add(condition.ToString()); }
                        }
                        catch (Exception) { };

                        wuser.Profiles.Add(wprofile);
                        max--;
                        if (max == 0) break;
                    }
                }

                catch (Exception) { };

                return wuser;
        }