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));
        }
        protected async override Task <IEnumerable <SelectListItem> > GetSelectListItemsAsync(SelectListContext context)
        {
            var dataValueField = nameof(DirectoryInfo.FullName);

            if (!Path.EndsWith(@"\"))
            {
                Path = Path + @"\";
            }

            var hostingEnvironment = context.HttpContext.RequestServices.GetRequiredService <IHostingEnvironment>();
            var mappedWwwPath      = hostingEnvironment.MapWwwPath(Path);
            var mappedContentPath  = hostingEnvironment.MapContentPath(Path);

            var searchPath = Path;
            var webFolder  = false;
            var root       = "";

            if (mappedWwwPath != mappedContentPath)
            {
                searchPath = mappedContentPath;
                root       = hostingEnvironment.ContentRootPath + @"\";
                if (Directory.Exists(mappedWwwPath))
                {
                    webFolder  = true;
                    searchPath = mappedWwwPath;
                    root       = hostingEnvironment.WebRootPath + @"\";
                }
            }

            var repository = _fileSystemGenericRepositoryFactory.CreateFolderRepositoryReadOnly(default(CancellationToken), searchPath, IncludeSubDirectories, SearchPattern, AtLeastOneFile);
            var data       = await repository.GetAllAsync(LamdaHelper.GetOrderByFunc <DirectoryInfo>(OrderByProperty, OrderByType), null, null);

            var results = new List <SelectListItem>();

            foreach (var item in data)
            {
                IHtmlHelper html = context.CreateHtmlHelper((dynamic)item);

                results.Add(new ModelSelectListItem()
                {
                    Model = item,
                    Html  = html,
                    Text  = RemoveSearchPathFromText ? context.Eval(html, item, DataTextFieldExpression).Replace(searchPath, "") : context.Eval(html, item, DataTextFieldExpression),
                    Value = RootRelativeValue ? webFolder ? context.Eval(html, item, dataValueField).Replace(root, "").Replace(@"\", @"/") : context.Eval(html, item, dataValueField).Replace(root, "") : context.Eval(html, item, dataValueField),
                });
            }

            return(results);
        }