예제 #1
0
        /// <summary>
        /// This method returns all details like First thumbnail of album, Title, user's details to show in Home page
        /// </summary>
        /// <returns></returns>
        public IEnumerable <AlbumViewModel> GetAlbumList()
        {
            var albumSVC  = factoryRepository.AlbumService();
            var albumRepo = new AlbumRepository(albumSVC);

            var userSVC  = factoryRepository.UserService();
            var userRepo = new UserRepository(userSVC);

            var photoSVC  = factoryRepository.PhotoService();
            var photoRepo = new PhotoRepository(photoSVC);

            List <AlbumViewModel>    albumList = new List <AlbumViewModel>();
            IEnumerable <UserModel>  users     = null;
            IEnumerable <AlbumModel> albums    = null;
            IEnumerable <PhotoModel> photos    = null;

            //Get Titles from API
            albums = albumRepo.FetchAlbums();

            //Get User details from API
            users = userRepo.FetchUsers();

            //Get Thumbnails from API
            photos = photoRepo.FetchPhotos();

            albumList = (from album in albums
                         from user in users.Where(u => u.Id == album.UserId)
                         from photo in photos.Where(p => p.AlbumId == album.Id)
                         .Take(1)
                         .DefaultIfEmpty()
                         select new AlbumViewModel
            {
                Id = album.Id,
                UserId = user.Id,
                Title = album.Title,
                Name = user.Name,
                Email = user.Email,
                Phone = user.Phone,
                Address = user.Address,
                ThumbnailUrl = photo.ThumbnailUrl
            }).ToList();

            return(albumList);
        }
예제 #2
0
        /// <summary>
        /// This method returns user details filtered by user id
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public PhotoViewModel FetchPhotosByAlbumId(int albumId)
        {
            var albumSVC  = factoryRepository.AlbumService();
            var albumRepo = new AlbumRepository(albumSVC);

            var photoSVC  = factoryRepository.PhotoService();
            var photoRepo = new PhotoRepository(photoSVC);

            PhotoViewModel           photoList = null;
            IEnumerable <PhotoModel> photos    = null;
            AlbumModel album = null;

            album  = albumRepo.FetchAlbums().Where(a => a.Id == albumId).FirstOrDefault();
            photos = photoRepo.FetchPhotos();
            photos = photos.Where(p => p.AlbumId == albumId).ToList();

            photoList = new PhotoViewModel()
            {
                AlbumId = album.Id,
                Title   = album.Title,
                Photo   = photos
            };
            return(photoList);
        }