public OwnerVehicleViewModel GetOwnerVehicleInfo(string registrationNumber) { var viewModel = new OwnerVehicleViewModel(); var Num = registrationNumber; using (var connection = new SqlConnection(_dBAccess.sqlConnection)) { SqlCommand cmd = new SqlCommand("[dbo].[GetOwnerVehicleInfoByRegistrationNumber]", connection) { CommandType = CommandType.StoredProcedure, }; cmd.Parameters.Add("@RegistrationNumber", SqlDbType.NVarChar).Value = registrationNumber; connection.Open(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { viewModel.Vehicle = MapVehicleInfo(reader); viewModel.Owner = MapOwnerInfo(reader); } } connection.Close(); } return(viewModel); }
public ViewResult SearchForVehicle(Vehicle vehicle) { var viewModel = new OwnerVehicleViewModel(); if (!string.IsNullOrWhiteSpace(vehicle.RegistrationNumber)) { viewModel = _appService.GetOwnerVehicleInfo(vehicle.RegistrationNumber); } return(View("../Vehicle/VehicleInfo", viewModel)); }