public async Task <TotalVendorDTO> SearchVendorsAsync(AdminSearchModel adminSearchModel) { var searchVendors = _vendorRepository.SearchVendors(adminSearchModel.SearchQuery); var sortBy = _discountRepository.GetSortType(adminSearchModel.SortBy[0]); var thenSortBy = _discountRepository.GetSortType(adminSearchModel.SortBy[1]); var orderedVendorDTOs = _vendorRepository.SortBy(searchVendors, sortBy); orderedVendorDTOs = _vendorRepository.ThenSortBy(orderedVendorDTOs, thenSortBy); var specifiedAmountOfVendors = await _vendorRepository.GetSpecifiedAmountAsync(orderedVendorDTOs, adminSearchModel.Skip, adminSearchModel.Take); var vendorDTOs = _mapper.Map <VendorDTO[]>(specifiedAmountOfVendors); for (int i = 0; i < vendorDTOs.Length; i++) { await AddRatingAndTicketCountToVendorAsync(vendorDTOs[i]); } TotalVendorDTO totalVendorDTO = new TotalVendorDTO() { VendorDTOs = vendorDTOs, TotalNumberOfVendors = await _vendorRepository.GetTotalNumberOfVendorsAsync(searchVendors), }; return(totalVendorDTO); }
public async Task <TotalDiscountDTO> SearchDiscountsForStatisticsAsync(AdminSearchModel adminSearchModel) { var discounts = _discountRepository.SearchStatisticDiscountsAsync(adminSearchModel.SearchQuery); var sortBy = _discountRepository.GetSortType(adminSearchModel.SortBy[0]); var thenSortBy = _discountRepository.GetSortType(adminSearchModel.SortBy[1]); var sortedDiscounts = _discountRepository.SortBy(discounts, sortBy); sortedDiscounts = _discountRepository.ThenSortBy(sortedDiscounts, thenSortBy); var specifiedAmountDiscounts = await _discountRepository.GetSpecifiedAmountAsync(sortedDiscounts, adminSearchModel.Skip, adminSearchModel.Take); var statisticDiscountDTOs = _mapper.Map <DiscountStatisticDTO[]>(specifiedAmountDiscounts); for (int i = 0; i < specifiedAmountDiscounts.Count(); i++) { var discountId = specifiedAmountDiscounts.ElementAt(i).Id; statisticDiscountDTOs[i].DiscountRating = await _discountRepository.GetDiscountRatingAsync(discountId); statisticDiscountDTOs[i].TicketCount = await _discountRepository.GetDiscountTicketCountAsync(discountId); } TotalDiscountDTO totalDiscountDTO = new TotalDiscountDTO() { DiscountDTOs = statisticDiscountDTOs, TotalNumberOfDiscounts = await _discountRepository.GetTotalNumberOfDiscountsAsync(discounts), }; return(totalDiscountDTO); }
public async Task <IActionResult> SearchVendors(AdminSearchModel searchmodel) { return(Ok(await _vendorService.SearchVendorsAsync(searchmodel))); }
public async Task <IActionResult> SearchDiscountsForStatistics(AdminSearchModel adminSearchModel) { return(Ok(await _discountService.SearchDiscountsForStatisticsAsync(adminSearchModel))); }