private async void frmViewAllVehicles_Load(object sender, EventArgs e) { var result = await _service.Get <List <Data.Model.Vehicle> >(null); List <frmAllVehiclesVM> newList = new List <frmAllVehiclesVM>(); foreach (var item in result) { frmAllVehiclesVM form = new frmAllVehiclesVM { VehicleId = item.VehicleId, ManufacturerName = item.VehicleModel.Manufacturer.ManufacturerName, ModelName = item.VehicleModel.ModelName, Image = item.Image, RegistrationNumber = item.RegistrationNumber, Mileage = item.Mileage, Transmission = item.Transmission, NumberOfSeats = item.NumberOfSeats, FuelName = item.FuelType.FuelName, BranchName = item.Branch.BranchName }; newList.Add(form); } dgvVehicles.AutoGenerateColumns = false; dgvVehicles.DataSource = newList; }
private async void btnShowVehicles_Click(object sender, EventArgs e) { var search = new VehicleSearchRequest() { ManufacturerName = txtSearchVehicle.Text, ModelName = txtModelName.Text, Transmission = txtTransmission.Text, RegistrationNumber = txtRegistrationNumber.Text, FuelName = txtFuelName.Text, BranchName = txtBranchName.Text }; var result = await _service.Get <List <Data.Model.Vehicle> >(search); List <frmAllVehiclesVM> finalList = new List <frmAllVehiclesVM>(); foreach (var item in result) { frmAllVehiclesVM form = new frmAllVehiclesVM { VehicleId = item.VehicleId, ManufacturerName = item.VehicleModel.Manufacturer.ManufacturerName, ModelName = item.VehicleModel.ModelName, RegistrationNumber = item.RegistrationNumber, Image = item.Image, Mileage = item.Mileage, Transmission = item.Transmission, NumberOfSeats = item.NumberOfSeats, FuelName = item.FuelType.FuelName, BranchName = item.Branch.BranchName }; finalList.Add(form); } dgvVehicles.AutoGenerateColumns = false; dgvVehicles.DataSource = finalList; if (finalList.Count == 0) { MessageBox.Show("There are no results for this search", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }