Esempio n. 1
0
        public async Task <IActionResult> Index()
        {
            //provjeri ako je sve dobro preneseno, like, feature itd
            var user = await _userManager.GetUserAsync(HttpContext.User);

            IndexViewModelHome model = new IndexViewModelHome();
            List <Photo>       photosFromSubscribers = null;

            if (user != null)
            {
                photosFromSubscribers = await _repository.GetPhotosFromSubscribedUsersAsync(user.Id);

                foreach (Photo photo in photosFromSubscribers)
                {
                    User owner = await _repository.GetUserId(photo.Id);

                    model.Photos.Add(new PhotoFavViewModel(photo, owner));
                }
            }

            List <Photo> featuredPhotos = await _repository.GetFeaturedPhotosAsync();

            foreach (Photo photo in featuredPhotos)
            {
                User owner = await _repository.GetUserId(photo.Id);

                if (photosFromSubscribers == null)
                {
                    model.Photos.Add(new PhotoFavViewModel(photo, owner));
                    continue;
                }

                if (photosFromSubscribers.Contains(photo))
                {
                    continue;
                }
                model.Photos.Add(new PhotoFavViewModel(photo, owner));
            }
            return(View(model));
        }
        public async Task <IActionResult> Index()
        {
            var user = await _userManager.GetUserAsync(HttpContext.User);

            FavoriteViewModel viewModel = new FavoriteViewModel();
            List <Photo>      favorites = await _repository.GetFavoritePhotos(user.Id);

            foreach (Photo photo in favorites)
            {
                if (photo == null)
                {
                    continue;
                }
                User owner = await _repository.GetUserId(photo.Id);

                viewModel.Photos.Add(new PhotoFavViewModel(photo, owner));
            }
            return(View(viewModel));
        }