Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        public IActionResult Inventory(int?id)
        {
            ManageAddInventoryViewModel manageAddInventoryViewModel;

            if (!id.HasValue)
            {
                manageAddInventoryViewModel = new ManageAddInventoryViewModel()
                {
                    TypeList = _outdoorPowerRepository.GetInventoryTypes().Select(
                        pt => new SelectListItem
                    {
                        Value = pt.Id.ToString(),
                        Text  = pt.Name
                    }).ToList(),
                    MakeList = _outdoorPowerRepository.GetInventoryMakes().Select(
                        pt => new SelectListItem
                    {
                        Value = pt.Id.ToString(),
                        Text  = pt.Name
                    }).ToList()
                };

                manageAddInventoryViewModel.MakeList.Add(new SelectListItem
                {
                    Value = "-2",
                    Text  = "Other"
                });

                manageAddInventoryViewModel.TypeList[0].Selected = true;
            }
            else
            {
                DealerInventory dealerInventory = _outdoorPowerRepository.GetDealerInventory((int)id);

                // Verify the inventory belongs to same dealer.
                string dealerId = User.Claims.FirstOrDefault(x => x.Type == "DealerId").Value;
                if (dealerInventory.DealerId != Int32.Parse(dealerId))
                {
                    return(RedirectPermanent("/Identity/Account/AccessDenied"));
                }

                manageAddInventoryViewModel = Mapper.Map <ManageAddInventoryViewModel>(dealerInventory);

                manageAddInventoryViewModel.TypeList = _outdoorPowerRepository.GetInventoryTypes().Select(
                    pt => new SelectListItem
                {
                    Value = pt.Id.ToString(),
                    Text  = pt.Name
                }).ToList();

                manageAddInventoryViewModel.MakeList = _outdoorPowerRepository.GetInventoryMakes().Select(
                    pt => new SelectListItem
                {
                    Value = pt.Id.ToString(),
                    Text  = pt.Name
                }).ToList();

                manageAddInventoryViewModel.MakeList.Add(new SelectListItem
                {
                    Value = "-2",
                    Text  = "Other"
                });

                if (manageAddInventoryViewModel.QInventoryMakeId > 0 && manageAddInventoryViewModel.QInventoryTypeId > 0)
                {
                    manageAddInventoryViewModel.ModelList = _outdoorPowerRepository.GetInventoryModels(
                        (int)manageAddInventoryViewModel.QInventoryMakeId,
                        manageAddInventoryViewModel.QInventoryTypeId
                        ).Select(
                        pt => new SelectListItem
                    {
                        Value = pt.Id.ToString(),
                        Text  = pt.Name
                    }
                        ).ToList();

                    manageAddInventoryViewModel.ModelList.Add(new SelectListItem
                    {
                        Value = "-2",
                        Text  = "Other"
                    });

                    if (manageAddInventoryViewModel.QInventoryModelId > 0)
                    {
                        manageAddInventoryViewModel.ModelOptionList = _outdoorPowerRepository.GetInventoryModelOptions(
                            (int)manageAddInventoryViewModel.QInventoryModelId
                            ).Select(
                            pt => new SelectListItem
                        {
                            Value = pt.Id.ToString(),
                            Text  = pt.Name
                        }
                            ).ToList();

                        manageAddInventoryViewModel.ModelOptionList.Add(new SelectListItem
                        {
                            Value = "-2",
                            Text  = "Other"
                        });
                    }

                    if (!String.IsNullOrEmpty(manageAddInventoryViewModel.EngineBrand))
                    {
                        manageAddInventoryViewModel.EngineHorsePowerList = _outdoorPowerRepository.GetEngineHorsePower(
                            manageAddInventoryViewModel.EngineBrand
                            ).Select(
                            pt => new SelectListItem
                        {
                            Value = pt,
                            Text  = pt
                        }
                            ).ToList();
                    }
                }

                manageAddInventoryViewModel.ImageList = _outdoorPowerRepository.GetDealerInventoryImages((int)id);
            }

            manageAddInventoryViewModel.YearList = new List <SelectListItem>();

            int year = DateTime.UtcNow.Year;

            do
            {
                manageAddInventoryViewModel.YearList.Add(
                    new SelectListItem()
                {
                    Text  = year.ToString(),
                    Value = year.ToString()
                }
                    );
                year -= 1;
            } while (year > 1995);

            manageAddInventoryViewModel.EngineBrandList = _outdoorPowerRepository.GetEngineBrands().Select(
                pt => new SelectListItem
            {
                Value = pt,
                Text  = pt
            }
                ).ToList();

            return(View(manageAddInventoryViewModel));
        }