public IActionResult QTypes() { try { var data = _outdoorPowerRepository.GetInventoryTypes(); return(Ok(data)); } catch (Exception ex) { _logger.LogError($"An error occurred when retrieving the Inventory Type List, Error Message: {ex}"); } return(BadRequest("Failed to retrieve the inventory type list.")); }
public IActionResult Index() { ViewBag.Title = "Welcome to Outdoor Power!"; var homeIndexViewModel = new HomeIndexViewModel() { Title = "Welcome to Outdoor Power!", 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 }) }; homeIndexViewModel.TypeList[0].Selected = true; return(View(homeIndexViewModel)); }
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)); }