public async Task <IViewComponentResult> InvokeAsync() { var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken()); IEnumerable <FaqDto> data = null; int total = 0; var dataTask = Service.GetAllAsync(cts.Token, LamdaHelper.GetOrderBy <FaqDto>(nameof(FaqDto.DateCreated), "asc"), null, null, false, false, null); var totalTask = Service.GetCountAsync(cts.Token); await TaskHelper.WhenAllOrException(cts, dataTask, totalTask); data = dataTask.Result; total = totalTask.Result; var response = new WebApiPagedResponseDto <FaqDto> { Page = 1, PageSize = total, Records = total, Rows = data.ToList() }; ViewBag.Page = 1; ViewBag.PageSize = total; return(View(response)); }
public async Task <IViewComponentResult> InvokeAsync() { string orderColumn = nameof(TestimonialDto.DateCreated); string orderType = OrderByType.Descending; var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken()); IEnumerable <TestimonialDto> testimonials = null; var testimonialsTask = _testimonialService.GetAllAsync(cts.Token, LamdaHelper.GetOrderBy <TestimonialDto>(orderColumn, orderType), null, null); await TaskHelper.WhenAllOrException(cts, testimonialsTask); testimonials = testimonialsTask.Result; var viewModel = new TestimonialsViewModel { Testimonials = testimonials.ToList() }; return(View(viewModel)); }
public async Task <IViewComponentResult> InvokeAsync() { string orderColumn = nameof(ProjectDto.DateCreated); string orderType = "desc"; var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken()); IEnumerable <ProjectDto> projects = null; var projectsTask = _projectService.GetAllAsync(cts.Token, LamdaHelper.GetOrderBy <ProjectDto>(orderColumn, orderType), null, null); await TaskHelper.WhenAllOrException(cts, projectsTask); projects = projectsTask.Result; var viewModel = new ProjectsViewModel { Projects = projects.ToList() }; return(View(viewModel)); }
public async Task <ActionResult> Index(int page = 1, int pageSize = 20, string orderColumn = nameof(LocationDto.Name), string orderType = "asc", string search = "") { var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken()); try { var dataTask = _locationService.SearchAsync(cts.Token, LocationType.Country.ToString() + "&" + search, l => !string.IsNullOrEmpty(l.Album) && !string.IsNullOrEmpty(l.UrlSlug), LamdaHelper.GetOrderBy <LocationDto>(orderColumn, orderType), page - 1, pageSize); var totalTask = _locationService.GetSearchCountAsync(cts.Token, LocationType.Country.ToString() + "&" + search, l => !string.IsNullOrEmpty(l.Album) && !string.IsNullOrEmpty(l.UrlSlug)); await TaskHelper.WhenAllOrException(cts, dataTask, totalTask); var data = dataTask.Result; var total = totalTask.Result; var response = new WebApiPagedResponseDto <LocationDto> { Page = page, PageSize = pageSize, Records = total, Rows = data.ToList(), OrderColumn = orderColumn, OrderType = orderType, Search = search }; ViewBag.Search = search; ViewBag.Page = page; ViewBag.PageSize = pageSize; ViewBag.OrderColumn = orderColumn; ViewBag.OrderType = orderType; return(View(response)); } catch { return(HandleReadException()); } }
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)); }