public IActionResult Index() { int dealerId = int.Parse(User.Claims.FirstOrDefault(x => x.Type == "DealerId").Value); ManageIndexViewModel manageIndexViewModel = new ManageIndexViewModel() { DealerId = dealerId, DealerEmployees = _outdoorPowerRepository.GetDealerEmployees(dealerId), MonthToDateMetrics = _metricRepository.GetMonthToDateMetrics(dealerId), YearToDateMetrics = _metricRepository.GetYearToDateMetrics(dealerId), UnitsSoldMetrics = _metricRepository.GetUnitsSoldMetrics(dealerId), MonthlyRevenue = _metricRepository.GetMonthlyRevenue(dealerId), YearlyRevenue = _metricRepository.GetYearlyRevenue(dealerId) }; manageIndexViewModel.SearchResults = _outdoorPowerRepository.SearchInventory(manageIndexViewModel); if (manageIndexViewModel.SearchResults != null) { IEnumerable <int> ids = manageIndexViewModel.SearchResults.Select(c => c.Id).Distinct(); List <Customer> customers = _metricRepository.GetCustomers(ids); List <SalesInfoModalViewModel> salesInfo = _metricRepository.GetSalesInfo(ids); foreach (DealerInventory result in manageIndexViewModel.SearchResults) { result.Customers = customers.Where(c => c.OPInventoryId == result.Id).ToList(); result.SalesInfo = salesInfo.Where(c => c.Id == result.Id).ToList(); } } return(View(manageIndexViewModel)); }
public IActionResult Search() { HomeSearchViewModel homeSearchViewModel = new HomeSearchViewModel() { EngineBrandList = _outdoorPowerRepository.GetEngineBrands().Select( pt => new SelectListItem { Value = pt, Text = pt } ).ToList(), MakeList = _outdoorPowerRepository.GetInventoryMakes().Select( pt => new SelectListItem { Value = pt.Id.ToString(), Text = pt.Name }).ToList(), TypeList = _outdoorPowerRepository.GetInventoryTypes().Select( pt => new SelectListItem { Value = pt.Id.ToString(), Text = pt.Name }).ToList() }; homeSearchViewModel.SearchResults = _outdoorPowerRepository.SearchInventory(homeSearchViewModel); homeSearchViewModel.NavStart = 1; homeSearchViewModel.NavEnd = homeSearchViewModel.TotalResults / homeSearchViewModel.ResultsPerPage; if (homeSearchViewModel.TotalResults % homeSearchViewModel.ResultsPerPage > 0) { homeSearchViewModel.NavEnd += 1; } // Since this is the first search, we can safely use a static "1" for the start nav, // and "5" for the end nav if (homeSearchViewModel.NavEnd > 7) { homeSearchViewModel.NavEnd = 7; } return(View(homeSearchViewModel)); }