Beispiel #1
0
        public IActionResult QModels(int makeId, int typeId)
        {
            try
            {
                var data = _outdoorPowerRepository.GetInventoryModels(makeId, typeId);
                return(Ok(data));
            }
            catch (Exception ex)
            {
                _logger.LogError($"An error occurred when retrieving the Inventory Model List,  Error Message: {ex}");
            }

            return(BadRequest("Failed to retrieve the inventory model list."));
        }
Beispiel #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));
        }
Beispiel #3
0
        public IActionResult Search(HomeSearchViewModel homeSearchViewModel)
        {
            homeSearchViewModel.TypeList = _outdoorPowerRepository.GetInventoryTypes().Select(
                pt => new SelectListItem
            {
                Value = pt.Id.ToString(),
                Text  = pt.Name
            }).ToList();

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

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

            if (homeSearchViewModel.QMake > 0)
            {
                homeSearchViewModel.ModelList = _outdoorPowerRepository.GetInventoryModels(
                    typeId: homeSearchViewModel.QType,
                    inventoryMakeId: homeSearchViewModel.QMake
                    ).Select(
                    pt => new SelectListItem
                {
                    Value = pt.Id.ToString(),
                    Text  = pt.Name
                }).ToList();
            }

            if (homeSearchViewModel.QModel > 0)
            {
                homeSearchViewModel.QModelOptionList = _outdoorPowerRepository.GetInventoryModelOptions(
                    inventoryModelId: homeSearchViewModel.QModel
                    ).Select(
                    pt => new SelectListItem
                {
                    Value = pt.Id.ToString(),
                    Text  = pt.Name
                }).ToList();
            }

            homeSearchViewModel.SearchResults = _outdoorPowerRepository.SearchInventory(homeSearchViewModel);

            homeSearchViewModel.NavStart = homeSearchViewModel.PageNum;
            homeSearchViewModel.NavEnd   = homeSearchViewModel.TotalResults / homeSearchViewModel.ResultsPerPage;

            if (homeSearchViewModel.TotalResults % homeSearchViewModel.ResultsPerPage > 0)
            {
                homeSearchViewModel.NavEnd += 1;
            }

            if (homeSearchViewModel.NavStart <= 7)
            {
                homeSearchViewModel.NavStart = 1;
            }
            else if (homeSearchViewModel.NavStart > 7)
            {
                homeSearchViewModel.NavEnd -= 2;
            }

            if (homeSearchViewModel.NavEnd > homeSearchViewModel.NavStart + 7)
            {
                homeSearchViewModel.NavEnd = homeSearchViewModel.NavStart + 7;
            }

            return(View(homeSearchViewModel));
        }