public ActionResult List()
        {
            var photos = DatabaseSession
                         .Query <Photo>()
                         .ToList();

            var recentlyUploaded = photos.OrderByDescending(x => x.InsertedDateTime).ThenByDescending(x => x.PhotoId).Take(10).ToList();
            var ran        = new Random();
            var randomSet  = new HashSet <Photo>();
            var randomList = new List <Photo>(photos);

            while (randomSet.Count < 10)
            {
                var nextIndex = ran.Next(randomList.Count);
                var item      = randomList[nextIndex];
                randomList.Remove(item);
                randomSet.Add(item);
            }

            var viewModel = new ListPhotosViewModel();

            viewModel.RecentlyUploaded = recentlyUploaded.Select(x => new ListPhotosViewModel.Photo
            {
                PhotoLinkURL      = this.GetURL(c => c.GetPhotoDetail(x.PhotoId)),
                PhotoThumbnailURL = x.GetThumbnailFileURL(),
            }).ToList();
            viewModel.RandomPic = randomSet.Select(x => new ListPhotosViewModel.Photo
            {
                PhotoLinkURL      = this.GetURL(c => c.GetPhotoDetail(x.PhotoId)),
                PhotoThumbnailURL = x.GetThumbnailFileURL()
            }).ToList();
            return(new ViewModelResult(viewModel));
        }
Example #2
0
        public ActionResult List()
        {
            var photos = DatabaseSession
                .Query<Photo>()
                .ToList();

            var recentlyUploaded = photos.OrderByDescending(x => x.InsertedDateTime).ThenByDescending(x => x.PhotoId).Take(10).ToList();
            var ran = new Random();
            var randomSet = new HashSet<Photo>();
            var randomList = new List<Photo>(photos);
            while (randomSet.Count < 10)
            {
                var nextIndex = ran.Next(randomList.Count);
                var item = randomList[nextIndex];
                randomList.Remove(item);
                randomSet.Add(item);
            }

            var viewModel = new ListPhotosViewModel();
            viewModel.RecentlyUploaded = recentlyUploaded.Select(x => new ListPhotosViewModel.Photo
            {
                PhotoLinkURL = this.GetURL(c => c.GetPhotoDetail(x.PhotoId)),
                PhotoThumbnailURL = x.GetThumbnailFileURL(),
            }).ToList();
            viewModel.RandomPic = randomSet.Select(x => new ListPhotosViewModel.Photo
            {
                PhotoLinkURL = this.GetURL(c => c.GetPhotoDetail(x.PhotoId)),
                PhotoThumbnailURL = x.GetThumbnailFileURL()
            }).ToList();
            return new ViewModelResult(viewModel);
        }