public async Task <List <SwiperSliderViewModel> > GetAllSliders() { var customer = await _workContext.GetCurrentCustomerAsync(); var store = await _storeContext.GetCurrentStoreAsync(); var sliders = await _swiperSliderService.GetAllSlidersAsync(storeId : store.Id); var model = new List <SwiperSliderViewModel>(); if (sliders.Any()) { var sliderIds = sliders.Select(x => x.Id)?.ToArray(); var sliderItems = await _swiperSliderService.GetAllSliderItemsAsync(sliderIds, store.Id); foreach (var sliderItem in sliderItems) { var viewModel = new SwiperSliderViewModel { AlternateText = sliderItem.AlternateText, DisplayOrder = sliderItem.DisplayOrder, Url = sliderItem.Url }; var picture = await _pictureService.GetPictureByIdAsync(sliderItem.PictureId); (viewModel.PictureUrl, _) = await _pictureService.GetPictureUrlAsync(picture, _mediaSettings.MaximumImageSize); model.Add(viewModel); } } return(model); }
public virtual async Task <SwiperSliderItemListModel> PrepareSliderItemListModelAsync(SwiperSliderItemSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } var sliderItems = await _swiperSliderService.GetAllSliderItemsAsync( sliderIds : new int[] { searchModel.SliderId }, storeId : searchModel.SearchStoreId, pageIndex : (searchModel.Page - 1), pageSize : searchModel.PageSize, showHidden : true, overridePublished : (searchModel.SearchPublishedId == 0 ? null : searchModel.SearchPublishedId == 1)); var model = await new SwiperSliderItemListModel().PrepareToGridAsync(searchModel, sliderItems, () => { return(sliderItems.SelectAwait(async sliderItem => { return await PrepareSliderItemModelAsync(null, sliderItem); })); }); return(model); }