// // GET: /Profile/ public ActionResult Index() { List<Profile> wprofiles = new List<Models.Profile>(); var mprofiles = mdb.GetCollection("profiles").FindAll(); foreach (var mprofile in mprofiles) { Profile wprofile = new Profile(); try { wprofile.ID = mprofile["_id"].ToString(); } catch (Exception) { }; try { wprofile.name = mprofile["name"].ToString(); } catch (Exception) { }; try { wprofile.Age = Convert.ToInt16(mprofile["age"].ToString()); } catch (Exception) { }; try { wprofile.Gender = mprofile["gender"].ToString(); } catch (Exception) { }; try { wprofile.UserID = mprofile["profile_id"].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) { }; try { var locations = mprofile["locations"].AsBsonArray.ToList(); wprofile.LocationIDs = new List<string>(); foreach (var location in locations) { wprofile.LocationIDs.Add(location.ToString()); } } catch (Exception) { }; wprofiles.Add(wprofile); } return View(wprofiles); }
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; }