updateServiceMapping function

Future<ServiceMapping> updateServiceMapping(
  1. int? mappingId,
  2. String mapping,
  3. String vendor
)

Implementation

Future<ServiceMapping> updateServiceMapping(
    int? mappingId, String mapping, String vendor) async {
  HttpOverrides.global = new MyHttpOverrides();
  final response = await http.put(
    Uri.parse(
        'https://192.168.1.106:45455/api/ServiceMappingModels/$mappingId'),
    headers: <String, String>{
      'Content-Type': 'application/json; charset=UTF-8',
    },
    body: jsonEncode(<String, String>{
      'mappingId': mappingId.toString(),
      'mapping': mapping,
      'vendor': vendor
    }),
  );

  if (response.statusCode == 201) {
    // If the server did return a 201 CREATED response,
    // then parse the JSON.
    return ServiceMapping.fromJson(jsonDecode(response.body));
  } else {
    // If the server did not return a 201 CREATED response,
    // then throw an exception.
    throw Exception('Failed to create Service Mapping.');
  }
}