public async Task <IActionResult> OnGet(Int32?index) { Console.WriteLine($"/community/assetBrowser/findSporecast/{index}{Request.QueryString}"); string searchString = Request.Query["searchText"]; SearchString = searchString; bool searchName = !String.IsNullOrEmpty(searchString); // search aggregators using LINQ var aggregators = _aggregatorManager.GetAllAggregators() .Include(a => a.Author) .Include(a => a.Assets) .Where(a => ( (!searchName) || ( (a.Name.Contains(searchString)) || (a.Author.UserName.Contains(searchString)) ) ) ).OrderBy(a => a.Name); CurrentIndex = index ?? 0; NextIndex = CurrentIndex + 3; PreviousIndex = CurrentIndex - 3; SearchCount = await aggregators .CountAsync(); Aggregators = await aggregators .Skip(CurrentIndex) .Take(3) .ToArrayAsync(); var author = await _userManager.GetUserAsync(User); UserAggregators = await _aggregatorManager.FindByAuthorAsync(author); var aggregatorSubscriptions = await _aggregatorSubscriptionManager.FindAllByAuthorAsync(author); AggregatorSubscriptions = aggregatorSubscriptions.Select(s => s.AggregatorId) .ToArray(); return(Page()); }
public async Task <IActionResult> HandShake() { var user = await _userManager.GetUserAsync(User); var asset = await _assetManager.FindByIdAsync(user.NextAssetId); var aggregators = await _aggregatorManager.FindByAuthorAsync(user); var userSubscriptions = await _userSubscriptionManager.FindAllByAuthorAsync(user); var aggregatorSubscriptions = await _aggregatorSubscriptionManager.FindAllByAuthorAsync(user); var aggregatorSubscriptionCounts = new List <Int32>(); // retrieve subscription count for each aggregator foreach (var aggregator in aggregators) { var aggregatorSubscriptionCount = await _aggregatorSubscriptionManager.GetSubscriberCountAsync(aggregator); aggregatorSubscriptionCounts.Add(aggregatorSubscriptionCount); } // reserve new asset when // * user has no reserved asset // * user has a used asset if (user.NextAssetId == 0 || (asset != null && asset.Used)) { // when reserving a new asset fails, error out if (!await _assetManager.ReserveAsync(user)) { return(StatusCode(500)); } } return(AtomFeedBuilder.CreateFromTemplate( new HandshakeTemplate(user, aggregators, aggregatorSubscriptionCounts.ToArray(), userSubscriptions, aggregatorSubscriptions) ).ToContentResult()); }
public async Task <IActionResult> OnGet(Int64 id) { Console.WriteLine($"/community/assetBrowser/profile/{id}{Request.QueryString}"); ProfileUser = await _userManager.FindByIdAsync($"{id}"); CurrentUser = await _userManager.GetUserAsync(User); // make sure ProfileUser exists if (ProfileUser == null) { return(NotFound()); } Subscribed = await _userSubscriptionManager.FindAsync(CurrentUser, ProfileUser) != null; AchievementIndex = 0; NextAchievementIndex = 3; PreviousAchievementIndex = -1; AssetIndex = 0; NextAssetIndex = 10; PreviousAssetIndex = -1; AggregatorIndex = 0; NextAggregatorIndex = 5; PreviousAggregatorIndex = -1; var requestQuery = Request.Query; if (requestQuery.ContainsKey("achievementIndex") && Int32.TryParse(requestQuery["achievementIndex"], out Int32 achievementIndex)) { AchievementIndex = achievementIndex; NextAchievementIndex = achievementIndex + 3; PreviousAchievementIndex = achievementIndex - 3; } if (requestQuery.ContainsKey("assetIndex") && Int32.TryParse(requestQuery["assetIndex"], out Int32 creationIndex)) { AssetIndex = creationIndex; NextAssetIndex = creationIndex + 10; PreviousAssetIndex = creationIndex - 10; } if (requestQuery.ContainsKey("aggregatorIndex") && Int32.TryParse(requestQuery["aggregatorIndex"], out Int32 sporecastIndex)) { AggregatorIndex = sporecastIndex; NextAggregatorIndex = sporecastIndex + 5; PreviousAggregatorIndex = sporecastIndex - 5; } var unlockedAchievementIds = await _achievementManager.FindAllByAuthorAsync(ProfileUser); UnlockedAchievementCount = unlockedAchievementIds == null ? 0 : unlockedAchievementIds.Length; UnlockedAchievementIds = unlockedAchievementIds? .Reverse() .Skip(AchievementIndex) .Take(3) .ToArray(); var assets = await _assetManager.FindAllByUserIdAsync(ProfileUser.Id); AssetCount = assets == null ? 0 : assets.Length; Assets = assets? .OrderByDescending(a => a.Timestamp) .Skip(AssetIndex) .Take(10) .ToArray(); var aggregators = await _aggregatorManager.FindByAuthorAsync(ProfileUser); AggregatorCount = aggregators == null ? 0 : aggregators.Length; Aggregators = aggregators? .OrderByDescending(a => a.Timestamp) .Skip(AggregatorIndex) .Take(5) .ToArray(); var aggregatorSubscriptions = await _aggregatorSubscriptionManager.FindAllByAuthorAsync(CurrentUser); AggregatorSubscriptions = aggregatorSubscriptions .Select(s => s.AggregatorId) .ToArray(); return(Page()); }