public static VehicleModelCollection GetCollection(int vehicleMakeId)
        {
            VehicleModelCollection tempList = null;

            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_GetVehicleModel", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@QueryId", SelectTypeEnum.GetCollectionByID);
                    myCommand.Parameters.AddWithValue("@VehicleMakeId", vehicleMakeId);

                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            tempList = new VehicleModelCollection();
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }

                        }
                        myReader.Close();
                    }
                }
            }

            return tempList;
        }
Esempio n. 2
0
        private VehicleMakeModelDTOCollection ModelCollectionToDTO(VehicleModelCollection modelCollection)
        {
            VehicleMakeModelDTOCollection tempList = new VehicleMakeModelDTOCollection();
            VehicleMakeModelDTO tempItem;

            if(modelCollection != null)
            {
                foreach(VehicleModel item in modelCollection)
                {
                    tempItem = new VehicleMakeModelDTO();

                    tempItem.VehicleModelId = item.VehicleModelId;

                    if (!string.IsNullOrEmpty(item.VehicleModelName))
                        tempItem.ModelName = item.VehicleModelName;

                    if(item.Make!= null)
                    {
                        tempItem.VehicleMakeId = item.Make.VehicleMakeId;

                        if (!string.IsNullOrEmpty(item.Make.VehicleMakeName))
                            tempItem.MakeName = item.Make.VehicleMakeName;

                    }
                    tempList.Add(tempItem);
                }
            }
            return tempList;
        }