public async Task <IReadOnlyCollection <SearchResultProfileViewModel> > GetAllProfilesAsync(string userId) { var profiles = from profile in db.Profiles where profile.ApplicationUser.IsActive select new SearchResultProfileViewModel() { BannerImagePath = profile.BannerImage.FileName, BannerPositionX = profile.BannerPositionX, BannerPositionY = profile.BannerPositionY, ProfileThumbnailImagePath = profile.UserImage.FileName, UserName = profile.ApplicationUser.UserName, UserSummaryOfSelf = profile.SummaryOfSelf, IsFavoritedByCurrentUser = profile.FavoritedBy.Any(x => x.UserId == userId), ProfileId = profile.Id, UserId = profile.ApplicationUser.Id }; var result = await profiles.ToListAsync(); foreach (var profile in result) { profile.BannerImagePath = UserImageExtensions.GetPath(profile.BannerImagePath); profile.ProfileThumbnailImagePath = ProfileExtensions.GetThumbnailImagePath(profile.ProfileThumbnailImagePath); } return(result.AsReadOnly()); }
public async Task <IReadOnlyCollection <SearchResultProfileViewModel> > GetProfilesByTagNamesAsync(string[] tags, string userId) { var profiles = await(from profile in db.Profiles join tagSuggestions in db.TagSuggestions on profile.Id equals tagSuggestions.ProfileId where tags.Contains(tagSuggestions.Tag.Name) where profile.ApplicationUser.IsActive select new SearchResultProfileViewModel() { BannerImagePath = profile.BannerImage.FileName, BannerPositionX = profile.BannerPositionX, BannerPositionY = profile.BannerPositionY, ProfileThumbnailImagePath = profile.UserImage.FileName, UserName = profile.ApplicationUser.UserName, UserSummaryOfSelf = profile.SummaryOfSelf, IsFavoritedByCurrentUser = profile.FavoritedBy.Any(x => x.UserId == userId), ProfileId = profile.Id, UserId = profile.ApplicationUser.Id }) .Distinct() .ToListAsync(); foreach (var profile in profiles) { profile.BannerImagePath = UserImageExtensions.GetPath(profile.BannerImagePath); profile.ProfileThumbnailImagePath = ProfileExtensions.GetThumbnailImagePath(profile.ProfileThumbnailImagePath); } return(profiles.AsReadOnly()); }
/// <summary> /// Returns all uploaded images for profiles that the passed user id has marked as "favorite" /// </summary> /// <param name="userId"></param> /// <returns></returns> public async Task <IReadOnlyCollection <UploadedImageFeedViewModel> > GetFollowerUploadedImagesAsync(string userId) { Debug.Assert(!String.IsNullOrEmpty(userId)); var imagesUploadedByFavorites = (from userImages in db.UserImages join favoritedProfiles in db.FavoriteProfiles on userImages.ApplicationUser.Profile.Id equals favoritedProfiles.ProfileId where favoritedProfiles.UserId == userId where userImages.ApplicationUser.IsActive where userImages.IsBanner == false select new UploadedImageFeedViewModel() { DateOccurred = userImages.DateUploaded, UploaderProfileId = userImages.ApplicationUser.Profile.Id, UploaderProfileImagePath = userImages.ApplicationUser.Profile.UserImage.FileName, UploaderUserId = userImages.ApplicationUserId, UploaderUserName = userImages.ApplicationUser.UserName, Path = userImages.FileName }); var results = await imagesUploadedByFavorites.ToListAsync(); foreach (var image in results) { image.UploaderProfileImagePath = ProfileExtensions.GetThumbnailImagePath(image.UploaderProfileImagePath); image.UploadedImagesPaths = new List <UploadedImageViewModel>(); image.UploadedImagesPaths.Add(new UploadedImageViewModel() { Path = UserImageExtensions.GetPath(image.Path) }); } return(results.AsReadOnly()); }