Example #1
0
        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));
        }