private async Task <List <Models.VideoDetails> > GetRecommendedList() { //Emulating an API call await Task.Delay(1000); var recommendedVideos = new List <Models.VideoDetails>(); var rnd = new Random(); for (int repeat = 1; repeat <= 2; repeat++) { for (int i = 1; i <= 10; i++) { var video = new Models.VideoDetails { ChannelName = $"Creative Channel {i} Name", ChannelThumbnail = $@"..\..\..\img\avatars\{i}.jpg", Title = $"Absolutely Amazing Title of Video {i}", Thumbnail = $@"..\..\..\img\thumbnails\{i}.jpg", Views = (ulong)rnd.Next(100, 2000000), PublishedDate = DateTime.Now.AddDays(-rnd.Next(1000)).AddMinutes(-rnd.Next(60)) }; recommendedVideos.Add(video); } } return(recommendedVideos); }
private async Task LoadVideoList() { CreateCardPlaceHolders(); List <Models.VideoDetails> recommendedVideos = await GetRecommendedList(); int placeholdersCount = pnlVideos.Controls.Count; for (int i = 0; i < recommendedVideos.Count; i++) { Models.VideoDetails videoDetails = recommendedVideos[i]; VideoCardItem item; if (placeholdersCount > 0) { item = (VideoCardItem)pnlVideos.Controls[i]; placeholdersCount--; } else { item = new VideoCardItem(); pnlVideos.Controls.Add(item); } item.ChannelName = videoDetails.ChannelName; item.ChannelThumbnail = videoDetails.ChannelThumbnail; item.Title = videoDetails.Title; item.Thumbnail = videoDetails.Thumbnail; item.Views = videoDetails.Views; item.PublishedDate = videoDetails.PublishedDate; item.Refresh(); } while (placeholdersCount > 0) { pnlVideos.Controls.RemoveAt(pnlVideos.Controls.Count - 1); placeholdersCount--; } }