public async Task <PaginationViewModel <ModuleViewModel> > GetItemsAsync(string name, int skipCount = 0, int takeCount = 0) { var filterPaginatedSpecification = new ModuleFilterPaginatedSpecification(name, skip: skipCount, take: takeCount); var itemsOnPage = await _moduleRepository.ListAsync(filterPaginatedSpecification); var totalCount = await _moduleRepository.CountAsync(filterPaginatedSpecification); var vm = new PaginationViewModel <ModuleViewModel>() { rows = itemsOnPage.Select(item => new ModuleViewModel() { CreateDate = item.CreateDate, CreateUserId = item.CreateUserId, Icon = item.Icon, Id = item.Id, IsShow = item.IsShow, Levels = item.Levels, ModulePath = item.ModulePath, Name = item.Name, Order = item.Order, ParentId = item.ParentId, }).ToList(), total = totalCount }; return(vm); }
public async Task <HomeIndexViewModel> GetHomeIndexViewModel(int pageIndex, int itemsPerPage, int?categoryId, int?brandId) { int totalItems = await _productRepository.CountAsync(new ProductsFilterSpecification(categoryId, brandId)); var products = await _productRepository.ListAsync(new ProductFilterPaginatedSpecifition((pageIndex - 1) * itemsPerPage, itemsPerPage, categoryId, brandId)); var vm = new HomeIndexViewModel { Categories = await GetCategories(), Brands = await GetBrands(), Products = products .Select(x => new ProductViewModel { Id = x.Id, ProductName = x.ProductName, Description = x.Description, UnitPrice = x.UnitPrice, PhotoPath = string.IsNullOrEmpty(x.PhotoPath) ? "no-product-image.png" : x.PhotoPath }).ToList(), CategoryId = categoryId, BrandId = brandId, PaginationInfo = new PaginationInfoViewModel() { TotalItems = totalItems, TotalPages = (int)Math.Ceiling((decimal)totalItems / itemsPerPage), ActualPage = totalItems == 0 ? 0 : pageIndex, ItemsOnPage = products.Count } }; vm.PaginationInfo.Previous = vm.PaginationInfo.ActualPage <= 1 ? "disabled" : ""; vm.PaginationInfo.Next = vm.PaginationInfo.ActualPage >= vm.PaginationInfo.TotalPages ? "disabled" : ""; return(vm); }
public async Task Get_Album_Of_Specific_User_Should_Match_Album_Count() { var albumFilterSpecification = new AlbumFilterSpecification(1); var numberOfAlbums = await _albumRepository.CountAsync(albumFilterSpecification); Assert.Equal(10, numberOfAlbums); }
public async Task <TorrentsViewModel> GetTorrents(int pageIndex, int itemsPage, string searchText) { var filterSpecification = new CatalogFilterSpecification(searchText); var filterPaginatedSpecification = new CatalogFilterPaginatedSpecification(itemsPage * pageIndex, itemsPage, searchText); var torrentsOnPage = await _torrentRepository.ListAsync(filterPaginatedSpecification); var totalTorrents = await _torrentRepository.CountAsync(filterSpecification); var ci = new TorrentsViewModel { CatalogTorrents = torrentsOnPage.Select(x => new TorrentViewModel() { Id = x.Id, Title = x.Title, Size = x.Size, RegistredAt = x.RegistredAt }), SearchText = searchText, PaginationInfo = new PaginationInfoViewModel() { ActualPage = pageIndex, TorrentsPerPage = torrentsOnPage.Count, TotalTorrents = totalTorrents, TotalPages = int.Parse(Math.Ceiling((decimal)totalTorrents / itemsPage).ToString()) } }; ci.PaginationInfo.Previous = (ci.PaginationInfo.ActualPage == 0) ? "is-disabled" : ""; ci.PaginationInfo.Next = (ci.PaginationInfo.ActualPage == ci.PaginationInfo.TotalPages - 1) ? "is-disabled" : ""; return(ci); }
public async Task <HomeIndexViewModel> GetHomeIndexViewModel(int?categoryId, int?brandId, int pageId) { var spec = new ProductFilterPaginatedSpecification(categoryId, brandId, (pageId - 1) * Constants.ITEMS_PER_PAGE, Constants.ITEMS_PER_PAGE); var specAll = new ProductFilterSpecification(categoryId, brandId); var products = await _productRepository.ListAsync(spec); var allCount = await _productRepository.CountAsync(specAll); var totalPages = (int)Math.Ceiling(allCount / (double)Constants.ITEMS_PER_PAGE); return(new HomeIndexViewModel() { Products = products.Select(x => new ProductViewModel() { Id = x.Id, Name = x.Name, Price = x.Price, PictureUri = x.PictureUri }).ToList(), Categories = await GetCategoryListItems(), Brands = await GetBrandListItems(), PaginationInfo = new PaginationInfoViewModel() { ItemsOnPage = products.Count, TotalItems = allCount, CurrentPage = pageId, TotalPages = totalPages, HasPrevious = pageId > 1, HasNext = pageId < totalPages } }); }
public async Task <IActionResult> SingleMeme(int id, int commentPage) { int maxNumberOfPages = (await commentRepo.CountAsync(new CountCommentsOnMeme(id)) - 1) / 20 + 1; if (maxNumberOfPages == 0) { maxNumberOfPages = 1; } if (commentPage < 0 || commentPage > maxNumberOfPages) { return(NotFound()); } var memes = await memeRepo.GetAsync(new SingleMemeSpec(id)); var meme = memes.FirstOrDefault(); if (meme == null) { return(NotFound()); } var userId = this.GetCurrentUserId(); var memeUserPoint = await memeXdPointRepo.GetAsync(new MemeXdPointConcreteUserIdAndMemeIdSpec(userId, meme.Id)); var isMemeXdClicked = (userId == null || memeUserPoint.FirstOrDefault() == null) ? false : true; var comments = await commentRepo.GetAsync(new PageOfCommentsSingleMemeSpec(commentPage, id)); var commentViewModels = new List <CommentViewModel>(); foreach (var comment in comments) { var userPoint = await commentXdPointRepo.GetAsync(new CommentXdPointConcreteUserIdAndMemeIdSpec(userId, comment.Id)); var isXdClicked = (userId == null || userPoint.FirstOrDefault() == null) ? false : true; commentViewModels.Add(new CommentViewModel(comment, isXdClicked, configuration)); } var paginationViewModel = new PaginationViewModel() { ActionName = "SingleMeme", ControllerName = "Home", CurrentPage = commentPage, MaxNumberOfPages = maxNumberOfPages, AllRouteData = new Dictionary <string, string> { { "id", meme.Id.ToString() } }, AlternativePageName = "commentPage" }; return(View(new SingleMemeViewModel { MemeCardViewModel = new MemeCardViewModel(meme, isMemeXdClicked, configuration), CommentViewModels = commentViewModels, PaginationViewModel = paginationViewModel })); }
public override async Task <ActionResult <ListPagedCatalogItemResponse> > HandleAsync([FromQuery] ListPagedCatalogItemRequest request, CancellationToken cancellationToken) { var response = new ListPagedCatalogItemResponse(request.CorrelationId()); var filterSpec = new CatalogFilterSpecification(request.CatalogBrandId, request.CatalogTypeId); int totalItems = await _itemRepository.CountAsync(filterSpec, cancellationToken); var pagedSpec = new CatalogFilterPaginatedSpecification( skip: request.PageIndex * request.PageSize, take: request.PageSize, brandId: request.CatalogBrandId, typeId: request.CatalogTypeId); var items = await _itemRepository.ListAsync(pagedSpec, cancellationToken); response.CatalogItems.AddRange(items.Select(_mapper.Map <CatalogItemDto>)); foreach (CatalogItemDto item in response.CatalogItems) { item.PictureUri = _uriComposer.ComposePicUri(item.PictureUri); } if (request.PageSize > 0) { response.PageCount = int.Parse(Math.Ceiling((decimal)totalItems / request.PageSize).ToString()); } else { response.PageCount = totalItems > 0 ? 1 : 0; } return(Ok(response)); }
public async Task <HomeIndexViewModel> GetHomeIndexViewModel(int?categoryId, int?authorId, int page, int pageSize) { var spec = new ProductsWithAuthorSpecification(categoryId, authorId); var specPaginated = new ProductsWithAuthorSpecification(categoryId, authorId, (page - 1) * pageSize, pageSize); var totalItems = await _productRepository.CountAsync(spec); var totalPages = (int)Math.Ceiling((double)totalItems / pageSize); var products = await _productRepository.ListAsync(specPaginated); var vm = new HomeIndexViewModel() { Products = products.Select(x => new ProductViewModel() { Id = x.Id, Name = x.Name, PictureUri = x.PictureUri, Price = x.Price, AuthorName = x.Author?.FullName }).ToList(), Authors = await GetAuthors(), Categories = await GetCategories(), PaginationInfo = new PaginationInfoViewModel() { Page = page, ItemsOnPage = products.Count, TotalItems = totalItems, TotalPages = totalPages, HasPrev = page > 1, HasNext = page < totalPages } }; return(vm); }
public async Task <IActionResult> GetPaging([FromQuery] PagingSettings _pagingSettings) { Boolean hasPaging = false; int page = 1; int pageSize = appConfig.pageSize; if (_pagingSettings != null) { hasPaging = true; page = _pagingSettings.page ?? page; pageSize = _pagingSettings.pagesize ?? pageSize; } var totalItems = await _repository.CountAsync(); if (!hasPaging) { pageSize = totalItems; } int currentPage = page; int currentPageSize = pageSize; var totalPages = (int)Math.Ceiling((double)totalItems / pageSize); IEnumerable <dynamic> _items = await _repository.GetAllAsync(); JsonResult json = Json(_items.Skip((currentPage - 1) * currentPageSize) .Take(currentPageSize).ToList()); Response.AddPagination(page, pageSize, totalItems, totalPages); return(Ok(json)); }
public async Task <HomeIndexViewModel> GetHomeIndexViewModel(int?categoryId, int?authorId, int page, int pageSize) { //alttaki satır app core da ki spec ve ef deki list async ile çalışıyor. Include işlemi yaptık. Daha sonra filtre yaptık. var spec = new ProductsWithAuthorSpecification(categoryId, authorId); var specPaginated = new ProductsWithAuthorSpecification(categoryId, authorId, (page - 1) * pageSize, pageSize); var totalItems = await _productRepository.CountAsync(spec);//degistirdik count diye var products = await _productRepository.ListAsync(specPaginated); var totalPages = (int)Math.Ceiling((double)totalItems / pageSize); var vm = new HomeIndexViewModel() { Products = products.Select(x => new ProductViewModel() { Id = x.Id, Name = x.Name, PictureUri = x.PictureUri, Price = x.Price, AuthorName = x.Author?.FullName //yazar yoksa yazma }).ToList(), Authors = await GetAuthors(), Categories = await GetCategories(), PaginationInfo = new PaginationInfoViewModel() { Page = page, ItemsOnPage = products.Count, TotalItems = totalItems, TotalPages = totalPages, HasPrev = page > 1, HasNext = page < totalPages } }; return(vm); }
public async Task <ProductCatalogDto> ListProductsAsync(int pageIndex, int itemsPage, string orderBy, string search) { var filterPaginatedEspecification = new ProductFilterPaginatedSpecification(itemsPage * pageIndex, itemsPage, orderBy, search); var filterSpecification = new ProductFilterSpecification(orderBy, search); var itemsOnPage = await _productRepository.ListAsync(filterPaginatedEspecification); var totalItems = await _productRepository.CountAsync(filterSpecification); var products = new ProductCatalogDto() { Products = itemsOnPage.Select(s => s.MapProductDto()).ToList(), PaginationInfo = new PaginationInfoDto() { ActualPage = pageIndex, ItemsPerPage = itemsOnPage.Count, TotalItems = totalItems, TotalPages = int.Parse(Math.Ceiling(((decimal)totalItems / itemsPage)).ToString()) } }; products.PaginationInfo.Next = (products.PaginationInfo.ActualPage == products.PaginationInfo.TotalPages - 1) ? "is-disabled" : ""; products.PaginationInfo.Previous = (products.PaginationInfo.ActualPage == 0) ? "is-disabled" : ""; return(products); }
public async Task <IActionResult> Get(int skip, int take, string searchQuery = null) { IReadOnlyList <CropVariety> cropVarieties = await _repository.GetAsync(new CropVarietySpecification(skip, take, searchQuery)); if (cropVarieties.Any()) { PaginatedResponse <CropVarietyResponse> response = new() { Data = cropVarieties.Select(cv => _mapper.Map(cv)), Total = await _repository.CountAsync(new CropVarietySpecification(searchQuery)) }; return(Ok(response)); } return(NoContent()); }
public async Task <IActionResult> Get(int skip, int take, string searchQuery = null) { IReadOnlyList <WorkItem> workItems = await _repository.GetAsync(new WorkItemSpecification(skip, take, searchQuery)); if (workItems.Any()) { PaginatedResponse <WorkItemResponse> response = new() { Data = workItems.Select(wi => _mapper.Map(wi)), Total = await _repository.CountAsync(new WorkItemSpecification(searchQuery)) }; return(Ok(response)); } return(NoContent()); }
public async Task <IActionResult> Get(int skip, int take, string searchQuery = null) { IReadOnlyList <Product> products = await _repository.GetAsync(new ProductSpecification(skip, take, searchQuery)); if (products.Any()) { ApiResponse <ProductResponse> response = new() { Data = products.Select(p => _mapper.Map(p)), Total = await _repository.CountAsync(new ProductSpecification(searchQuery)) }; return(Ok(response)); } return(NoContent()); }
public async Task <int> BasketItemsCount(int basketId) { // basketId 'sine göre sepetteki kalem adedini say //basketItemspecification' da sepetId'leri eşleştirdik, eşleştirdiğimiz sepetin kalem adedini say. var spec = new BasketItemSpecification(basketId); return(await _basketItemRepository.CountAsync(spec)); }
public async Task <PaginatedList <Movie> > Handle(GetPaginatedMoviesQuery request, CancellationToken cancellationToken) { var paginatedMovies = await _repositoryAsync.ListAsync(new GetPaginatedMoviesWithItemsSpecification(request.SearchString, request.PageIndex, request.PageSize)); var totalItems = await _repositoryAsync.CountAsync(new GetMoviesSpecification(request.SearchString)); return(new PaginatedList <Movie>(paginatedMovies.ToList(), totalItems, request.PageIndex, request.PageSize)); }
public async Task <CatalogIndexViewModel> GetCatalogItems( int pageIndex, int itemsPage, string searchText, int?brandId, int?typeId, bool convertPrice = true, CancellationToken cancellationToken = default(CancellationToken)) { _logger.LogInformation("GetCatalogItems called."); var pageItemsOffset = itemsPage * pageIndex; var filterSpecification = new CatalogFilterSpecification(searchText, brandId, typeId); var filterPaginatedSpecification = new CatalogFilterPaginatedSpecification( pageItemsOffset, itemsPage, searchText, brandId, typeId); // the implementation below using ForEach and Count. We need a List. var itemsOnPage = await _itemRepository.ListAsync(filterPaginatedSpecification); // var itemsOnPage = await ListCatalogItems( // itemsPage * pageIndex, itemsPage, brandId, typeId); var totalItems = await _itemRepository.CountAsync(filterSpecification); // var totalItems = await CountCatalogItems(brandId, typeId); foreach (var itemOnPage in itemsOnPage) { itemOnPage.PictureUri = string.IsNullOrEmpty(itemOnPage.PictureUri) ? _configuration.GetValue <string>("ImagePictureUri") : _uriComposer.ComposePicUri(itemOnPage.PictureUri); } var CatalogItemsTask = Task.WhenAll(itemsOnPage.Select( catalogItem => CreateCatalogItemViewModelAsync(catalogItem, convertPrice, cancellationToken))); cancellationToken.ThrowIfCancellationRequested(); var vm = new CatalogIndexViewModel() { CatalogItems = await CatalogItemsTask, // catalogItemsList, Brands = await GetBrands(), Types = await GetTypes(), BrandFilterApplied = brandId ?? 0, TypesFilterApplied = typeId ?? 0, PaginationInfo = new PaginationInfoViewModel() { ActualPage = pageIndex, ItemsPerPage = itemsOnPage.Count, TotalItems = totalItems, TotalPages = int.Parse(Math.Ceiling(((decimal)totalItems / itemsPage)).ToString()) } }; vm.PaginationInfo.Next = (vm.PaginationInfo.ActualPage == vm.PaginationInfo.TotalPages - 1) ? "is-disabled" : ""; vm.PaginationInfo.Previous = (vm.PaginationInfo.ActualPage == 0) ? "is-disabled" : ""; return(vm); }
public async Task <int> GetDuplicateCount(int countryid, string name) { _sharedService.WriteLogs("GetDuplicateCount started by:" + _userSettings.UserName, true); try { var filterSpecification = new ProvinceFilterSpecification(countryid, name); var totalItems = await _provinceRepository.CountAsync(filterSpecification); return(totalItems); } catch (Exception ex) { _sharedService.WriteLogs("GetDuplicateCount failed:" + ex.Message, false); return(-1); } }
public async Task <int> GetDuplicateCount(string ediid) { _sharedService.WriteLogs("GetDuplicateCount started by:" + _userSettings.UserName, true); try { var filterSpecification = new ChildFilterSpecification(ediid); var totalItems = await _childRepository.CountAsync(filterSpecification); return(totalItems); } catch (Exception ex) { _sharedService.WriteLogs("GetDuplicateCount failed:" + ex.Message, false); return(-1); } }
public async Task <ListTransactionHistoryViewModel> GetTransactionHistory(EntityType entityType, int entityid, string daterange, int page, int pagesize) { var date = Common.Helpers.DateRangeHelper.GetDateRangeByDate(daterange); var walletid = await _walletRepository.GetWalletId(entityType, entityid); var filter = new TransactionHistorySpecification(walletid, date); var total = await _transactionHistoryRepository.CountAsync(filter); var transactionHistory = await _transactionHistoryRepository.ListPagedAsync(filter, "Id_desc", page, pagesize); return(new ListTransactionHistoryViewModel() { TransactionHistories = TransactionHistoryViewModel.GetList(transactionHistory), Pager = new PagerViewModel(page, pagesize, total) }); }
public async Task <int> GetDuplicateCount(int schoolid, string teachernumber) { _sharedService.WriteLogs("GetDuplicateCount started by:" + _userSettings.UserName, true); try { var filterSpecification = new TeacherFilterSpecification(schoolid, teachernumber); var totalItems = await _teacherRepository.CountAsync(filterSpecification); return(totalItems); } catch (Exception ex) { _sharedService.WriteLogs("GetDuplicateCount failed:" + ex.Message, false); return(-1); } }
public async Task <int> GetQCDuplicateCount(string entityname, string entityfield) { _sharedService.WriteLogs("GetQCDuplicateCount started by:" + _userSettings.UserName, true); try { var filterSpecification = new QuestionnaireConfigurationFilterSpecification(entityname, entityfield); var totalItems = await _questionnairesConfigurationRepository.CountAsync(filterSpecification); return(totalItems); } catch (Exception ex) { _sharedService.WriteLogs("GetQCDuplicateCount failed:" + ex.Message, false); return(-1); } }
public async Task <PaginatedList <ListDataBasesDTO> > Handle(GetListDataBesesWithPaginationQuery request, CancellationToken cancellationToken) { var list = await _dataBaseRepository.GetPagedReponseAsync(request.PageNumber, request.PageSize); var item = _mapper.Map <List <ListDataBasesDTO> >(list); var count = await _dataBaseRepository.CountAsync(); return(new PaginatedList <ListDataBasesDTO>(item, count, request.PageNumber, request.PageSize)); //return new ListDataBasesWithPaginationVM(item, count, request.PageNumber, request.PageSize); }
public async Task <ListCampaignAccountContentViewModel> GetCampaignAccountContents(int campaignAccountId, string order, int page, int pagesize) { var filter = new CampaignAccountContentByCampaignAccountIdSpecification(campaignAccountId); var total = await _CampaignAccountContentRepository.CountAsync(filter); var list = await _CampaignAccountContentRepository.ListPagedAsync(filter, "DateModified_desc", page, pagesize); return(new ListCampaignAccountContentViewModel() { CampaignAccountContents = CampaignAccountContentViewModel.GetList(list), Pager = new PagerViewModel() { Page = page, PageSize = pagesize, Total = total } }); }
public async Task<int> GetDuplicateCount(int yearnumber) { _sharedService.WriteLogs("GetDuplicateCount started by:" + _userSettings.UserName, true); try { var filterSpecification = new YearFilterSpecification(yearnumber); var totalItems = await _yearRepository.CountAsync(filterSpecification); return totalItems; } catch (Exception ex) { _sharedService.WriteLogs("GetDuplicateCount failed:" + ex.Message, false); return -1; } }
public async Task<int> BasketItemsCount(string buyerId) { if (!await BasketExistsAsync(buyerId)) { return 0; } var basketId = await GetBasketIdAsync(buyerId); var spec = new BasketItemSpecification(basketId); return await _basketItemRepository.CountAsync(spec); }
public override async Task <ActionResult <GetItemListResponse> > HandleAsync([FromQuery] GetItemListRequest request, CancellationToken cancellationToken = default) { var response = new GetItemListResponse(request.CorrelationId()); int totalItems = 0; var items = new List <ShopItem>().AsReadOnly() as IReadOnlyList <ShopItem>; if (request.PriceSpecification) { if (request.PriceFrom > request.PriceTo) { return(BadRequest("Price from can't be less than Price to")); } var filterSpec = new ItemFilterSpecification(request.PriceFrom, request.PriceTo); totalItems = await _itemRepository.CountAsync(filterSpec); var pagedSpec = new ItemFilterPaginatedSpecification( request.ItemsPerPage * (request.PageIndex - 1), request.ItemsPerPage, request.PriceFrom, request.PriceTo); items = await _itemRepository.ListAsync(pagedSpec); } else { var filterSpec = new ItemFilterSpecification(); totalItems = await _itemRepository.CountAsync(filterSpec); var pagedSpec = new ItemFilterPaginatedSpecification( request.ItemsPerPage * (request.PageIndex - 1), request.ItemsPerPage); items = await _itemRepository.ListAsync(pagedSpec); } response.Items.AddRange(items.Select(_mapper.Map <ItemDto>)); response.PageCount = int.Parse(Math.Ceiling((decimal)totalItems / request.ItemsPerPage).ToString()); return(Ok(response)); }
public async Task <Result <List <CatalogItemViewModel> > > Handle(GetCatalogItemsQuery request, CancellationToken cancellationToken) { var filterSpecification = new CatalogFilterSpecification(request.brandId, request.typeId); var filterPaginatedSpecification = new CatalogFilterPaginatedSpecification(request.itemsPage * request.pageIndex, request.itemsPage, request.brandId, request.typeId); // the implementation below using ForEach and Count. We need a List. var itemsOnPage = await _itemRepository.ListAsync(filterPaginatedSpecification); var totalItems = await _itemRepository.CountAsync(filterSpecification); return(default);
private bool BeUnique(Order order) { var Spec = new OrderByPONumberSpecification(order.PONumber, order.ClientGatewayId); var count = _asyncOrderRepository.CountAsync(Spec).Result; if (count > 0) { return(false); } return(true); }
public async Task <IActionResult> Index(int?page) { page ??= new int?(1); int maxNumberOfPages = (await memeRepo.CountAsync(new BaseSpecification <Meme>()) - 1) / 10 + 1; if (maxNumberOfPages == 0) { maxNumberOfPages = 1; } if (page.Value < 1 || page.Value > maxNumberOfPages) { return(NotFound()); } var userId = this.GetCurrentUserId(); var memes = await memeRepo.GetAsync(new PageOfMemesOrderedByDateSpec(page.Value)); var memeViewModels = new List <MemeCardViewModel>(); foreach (var meme in memes) { var userPoint = await memeXdPointRepo.GetAsync(new MemeXdPointConcreteUserIdAndMemeIdSpec(userId, meme.Id)); var isXdClicked = (userId == null || userPoint.FirstOrDefault() == null) ? false : true; memeViewModels.Add(new MemeCardViewModel(meme, isXdClicked, configuration)); } var paginationViewModel = new PaginationViewModel() { ActionName = "Index", ControllerName = "Home", CurrentPage = page.Value, MaxNumberOfPages = maxNumberOfPages }; return(View(new IndexViewModel { MemeCardViewModels = memeViewModels, PaginationViewModel = paginationViewModel })); }