public ViewResult List()
        {
            //return View(_vehicleRepo.GetAllVehicles);
            VehicleListVM vehicleListVM = new VehicleListVM
            {
                Vehicles             = _vehicleRepo.GetAllVehicles,
                SelectedCategoryName = _vehicleCategoryRepo.GetAllCategories.ToList()[0].Name
            };

            return(View(vehicleListVM));
        }
示例#2
0
        public async Task GetData()
        {
            dgvVehicleList.DataSource = null;
            List <Model.Vehicle> list;

            if (dgvVehicleList.Columns.Contains("btnDetails"))
            {
                dgvVehicleList.Columns.Remove("btnDetails");
            }
            int cmb = 0;

            if (cbBrand.SelectedValue != null)
            {
                cmb = int.Parse(cbBrand.SelectedValue.ToString());
            }

            if (!string.IsNullOrWhiteSpace(txtName.Text) || cmb > 0 || checkBox1.Checked || !checkBox1.Checked)
            {
                Model.Requests.Vehicle.VehicleSearchRequest searchString = new Model.Requests.Vehicle.VehicleSearchRequest()
                {
                    Name    = txtName?.Text,
                    BrandId = cmb
                };

                if (checkBox1.CheckState == CheckState.Checked || checkBox1.CheckState == CheckState.Unchecked)
                {
                    searchString.IsActive = checkBox1.Checked;
                }
                list = await _apiService.Get <List <Model.Vehicle> >(searchString);
            }
            else
            {
                list = await _apiService.Get <List <Model.Vehicle> >();
            }


            List <VehicleListVM> listvm = new List <VehicleListVM>();

            foreach (var item in list)
            {
                VehicleListVM vmitem = new VehicleListVM()
                {
                    Id               = item.Id,
                    Brand            = item.Brand.Name,
                    Name             = item.Name,
                    Price            = item.Price.ToString() + "KM",
                    VehicleModel     = item.VehicleModel.Name,
                    NumberOfSeats    = item.NumberOfSeats,
                    Description      = item.Description,
                    YearManufactured = item.YearManufactured,
                    Fuel             = item.Fuel.Name,
                    Transmission     = item.Transmission,
                    IsActive         = bool.Parse(item.IsActive.ToString())
                };

                listvm.Add(vmitem);
            }
            lblNoOfCars.Text                  = "Number of cars: " + listvm.Count();
            dgvVehicleList.DataSource         = listvm;
            dgvVehicleList.Columns[0].Visible = false;

            DataGridViewButtonColumn bcol = new DataGridViewButtonColumn();

            bcol.HeaderText = "Action";
            bcol.Text       = "Details";
            bcol.Name       = "btnDetails";

            bcol.UseColumnTextForButtonValue = true;
            if (!dgvVehicleList.Columns.Contains("btnDetails"))
            {
                dgvVehicleList.Columns.Add(bcol);
            }

            if (dgvVehicleList.RowCount == 0)
            {
                MessageBox.Show("No vehicles with that search query.", "Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }