Example #1
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            string orderColumn = nameof(CarouselItemDto.DateCreated);
            string orderType   = OrderByType.Descending;

            var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken());

            IEnumerable <BlogPostDto>     posts = null;
            IList <CarouselItemDto>       carouselItemsFinal = new List <CarouselItemDto>();
            IEnumerable <CarouselItemDto> carouselItems      = null;

            IList <DirectoryInfo>   albums             = new List <DirectoryInfo>();
            IList <CarouselItemDto> albumCarouselItems = new List <CarouselItemDto>();


            var postsTask         = _blogService.BlogPostApplicationService.GetPostsForCarouselAsync(0, 3, cts.Token);
            var carouselItemsTask = _carouselItemService.GetAsync(cts.Token, c => c.Published, LamdaHelper.GetOrderBy <CarouselItemDto>(orderColumn, orderType), null, null);

            await TaskHelper.WhenAllOrException(cts, postsTask, carouselItemsTask);

            posts         = postsTask.Result;
            carouselItems = carouselItemsTask.Result;

            var repository = _fileSystemRepository.CreateFolderRepositoryReadOnly(cts.Token, Server.GetWwwFolderPhysicalPathById(Folders.Gallery));

            foreach (CarouselItemDto item in carouselItems)
            {
                if (!string.IsNullOrEmpty(item.Album))
                {
                    var album = repository.GetByPath(item.Album);
                    if (album != null)
                    {
                        albums.Add(album);
                        albumCarouselItems.Add(item);
                    }
                }
                else
                {
                    carouselItemsFinal.Add(item);
                }
            }

            var carouselViewModel = new CarouselViewModel
            {
                Posts = posts.ToList(),

                Albums             = albums.ToList(),
                AlbumCarouselItems = albumCarouselItems.ToList(),

                CarouselItems = carouselItemsFinal.ToList(),
                ItemCount     = posts.Count() + albums.Count() + carouselItemsFinal.Count()
            };

            return(View(carouselViewModel));
        }
Example #2
0
        public async Task <IViewComponentResult> InvokeAsync()
        {
            string orderColumn = nameof(CarouselItemDto.CreatedOn) + " desc";

            var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken());

            IEnumerable <BlogPostDto>     posts = null;
            IList <CarouselItemDto>       carouselItemsFinal = new List <CarouselItemDto>();
            IEnumerable <CarouselItemDto> carouselItems      = null;

            IList <DirectoryInfo>   albums             = new List <DirectoryInfo>();
            IList <CarouselItemDto> albumCarouselItems = new List <CarouselItemDto>();

            posts = await _blogService.BlogPostApplicationService.GetPostsForCarouselAsync(0, 3, cts.Token);

            carouselItems = await _carouselItemService.GetAsync(cts.Token, c => c.Published, orderColumn, null, null);

            var repository = _fileSystemRepository.CreateFolderRepositoryReadOnly(cts.Token, _hostingEnvironment.MapWwwPath(_appSettings.Folders[Folders.Gallery]));

            foreach (CarouselItemDto item in carouselItems)
            {
                if (!string.IsNullOrEmpty(item.Album))
                {
                    var album = repository.GetByPath(item.Album);
                    if (album != null)
                    {
                        albums.Add(album);
                        albumCarouselItems.Add(item);
                    }
                }
                else
                {
                    carouselItemsFinal.Add(item);
                }
            }

            var carouselViewModel = new CarouselViewModel
            {
                Posts = posts.ToList(),

                Albums             = albums.ToList(),
                AlbumCarouselItems = albumCarouselItems.ToList(),

                CarouselItems = carouselItemsFinal.ToList(),
                ItemCount     = posts.Count() + albums.Count() + carouselItemsFinal.Count()
            };

            return(View(carouselViewModel));
        }