public AboutViewModel(User user, UserProfile userProfile, Image profilePicture) { ProfilePictureName = profilePicture.FileName; ProfilePicturePath = (profilePicture.Path != "no-image.png") ? user.UserID + "/" + profilePicture.Path : profilePicture.Path; HomeTown = (userProfile.HomeTown != null) ? PlaceViewModel.GetPlaceObjectt(userProfile.HomeTown) : new PlaceViewModel(); if (userProfile.PastLocal != null) { string[] userProfilePastLocals = userProfile.PastLocal.Split(','); foreach (string pl in userProfilePastLocals) { if (pl != "") { PastLocals.Add(PlaceViewModel.GetPlaceObjectt(pl)); } } } else { PastLocals.Add(new PlaceViewModel()); } LastTraveled = (userProfile.LastTraveled != null) ? PlaceViewModel.GetPlaceObjectt(userProfile.LastTraveled) : new PlaceViewModel(); if (userProfile.FavoritePlace != null) { string[] userProfileFavoritePlaces = userProfile.FavoritePlace.Split(','); foreach (string fp in userProfileFavoritePlaces) { if (fp != "") { FavoritePlaces.Add(PlaceViewModel.GetPlaceObjectt(fp)); } } } FirstName = user.FirstName; LastName = user.LastName; DOB = userProfile.DOB; DateTime now = DateTime.Today; Age = (now.Year - DOB.Year); if (now < DOB.AddYears(Age)) { Age--; } About = userProfile.About; Birthday = String.Format("{0:MMMM d}", DOB); MemberSince = String.Format("{0:M/d/yyyy}", user.DateJoined); }
public static PlaceViewModel GetPlaceObjectt(string placeID) { try { using (WebClient client = new WebClient()) { //string result = client.DownloadString(String.Format("https://maps.googleapis.com/maps/api/place/details/json?&placeid={0}&key=AIzaSyBI5B2snURiIE8VkeuNYL2Es3ZZf8veRf4", placeID)); string result = client.DownloadString(String.Format("https://maps.googleapis.com/maps/api/place/details/json?&placeid={0}&key=AIzaSyAuQaBzbJrduma-UhUFoWNyLWfJFoR3vac", placeID)); PlaceObject jsonObject = JsonConvert.DeserializeObject <PlaceObject>(result); PlaceViewModel placeViewModel = new PlaceViewModel(jsonObject); return(placeViewModel); } } catch (Exception) { throw; } }
} // Empty constructor public EditProfileViewModel(User user, UserProfile userProfile, PlaceViewModel homeTown, List <PlaceViewModel> pastLocal, List <PlaceViewModel> favoritePlace, PlaceViewModel lastTraveled, string imagepath, bool privateProfile) // Value passed constructor { UserID = user.UserID; FirstName = user.FirstName; LastName = user.LastName; About = userProfile.About; HomeTown = homeTown.FormattedAddress; HomeTownID = homeTown.PlaceID; HomeTownName = homeTown.Name; LastTraveled = lastTraveled.FormattedAddress; LastTraveledID = lastTraveled.PlaceID; LastTraveledName = lastTraveled.Name; ImagePath = imagepath; PrivateProfile = privateProfile; for (int i = 0; i < pastLocal.Count; i++) { if (pastLocal[i].PlaceID == null) { FirstEmptyPastLocal = String.Format("'pastLocal{0}Input'", i); break; } } PastLocal0 = pastLocal[0].FormattedAddress; PastLocal0ID = pastLocal[0].PlaceID; PastLocal0Name = pastLocal[0].Name; PastLocal1 = pastLocal[1].FormattedAddress; PastLocal1ID = pastLocal[1].PlaceID; PastLocal1Name = pastLocal[1].Name; PastLocal2 = pastLocal[2].FormattedAddress; PastLocal2ID = pastLocal[2].PlaceID; PastLocal2Name = pastLocal[2].Name; PastLocal3 = pastLocal[3].FormattedAddress; PastLocal3ID = pastLocal[3].PlaceID; PastLocal3Name = pastLocal[3].Name; PastLocal4 = pastLocal[4].FormattedAddress; PastLocal4ID = pastLocal[4].PlaceID; PastLocal4Name = pastLocal[4].Name; PastLocal5 = pastLocal[5].FormattedAddress; PastLocal5ID = pastLocal[5].PlaceID; PastLocal5Name = pastLocal[5].Name; PastLocal6 = pastLocal[6].FormattedAddress; PastLocal6ID = pastLocal[6].PlaceID; PastLocal6Name = pastLocal[6].Name; PastLocal7 = pastLocal[7].FormattedAddress; PastLocal7ID = pastLocal[7].PlaceID; PastLocal7Name = pastLocal[7].Name; PastLocal8 = pastLocal[8].FormattedAddress; PastLocal8ID = pastLocal[8].PlaceID; PastLocal8Name = pastLocal[8].Name; PastLocal9 = pastLocal[9].FormattedAddress; PastLocal9ID = pastLocal[9].PlaceID; PastLocal9Name = pastLocal[9].Name; for (int i = 0; i < favoritePlace.Count; i++) { if (favoritePlace[i].PlaceID == null) { FirstEmptyFavoritePlace = String.Format("'favoritePlace{0}Input'", i); break; } } FavoritePlace0 = favoritePlace[0].FormattedAddress; FavoritePlace0ID = favoritePlace[0].PlaceID; FavoritePlace0Name = favoritePlace[0].Name; FavoritePlace1 = favoritePlace[1].FormattedAddress; FavoritePlace1ID = favoritePlace[1].PlaceID; FavoritePlace1Name = favoritePlace[1].Name; FavoritePlace2 = favoritePlace[2].FormattedAddress; FavoritePlace2ID = favoritePlace[2].PlaceID; FavoritePlace2Name = favoritePlace[2].Name; FavoritePlace3 = favoritePlace[3].FormattedAddress; FavoritePlace3ID = favoritePlace[3].PlaceID; FavoritePlace3Name = favoritePlace[3].Name; FavoritePlace4 = favoritePlace[4].FormattedAddress; FavoritePlace4ID = favoritePlace[4].PlaceID; FavoritePlace4Name = favoritePlace[4].Name; DOB = userProfile.DOB.ToShortDateString(); PrivateProfile = privateProfile; }