let AI comment everything because well... yeah...
This commit is contained in:
@@ -1,25 +1,39 @@
|
||||
// * Shared method for saving templates to the database
|
||||
// * Handles both place and excursion templates
|
||||
// * Supports both creating new templates and updating existing ones
|
||||
|
||||
import 'package:fforte/enums/databases.dart';
|
||||
import 'package:fforte/interfaces/i_db.dart';
|
||||
import 'package:fforte/methods/excursion_db_helper.dart';
|
||||
import 'package:fforte/methods/place_db_helper.dart';
|
||||
|
||||
/// Save or update a template in the database
|
||||
/// @param templateData Map containing the template data
|
||||
/// @param dbType The type of database (place/excursion)
|
||||
/// @return ID of the saved template, or -1 if operation failed
|
||||
Future<int> saveTemplate(Map<String, String> templateData, DatabasesEnum dbType,) async {
|
||||
// Select appropriate database helper
|
||||
IDb dbHelper;
|
||||
int id =templateData["ID"]! != "" ? int.parse(templateData["ID"]!) : -1;
|
||||
int id = templateData["ID"]! != "" ? int.parse(templateData["ID"]!) : -1;
|
||||
|
||||
if (dbType == DatabasesEnum.place) {
|
||||
dbHelper = PlaceDBHelper();
|
||||
} else if (dbType == DatabasesEnum.excursion) {
|
||||
dbHelper = ExcursionDBHelper();
|
||||
} else {
|
||||
return -1;
|
||||
return -1; // Invalid database type
|
||||
}
|
||||
|
||||
// Remove sent status as it's not needed for templates
|
||||
templateData.remove("Sent");
|
||||
|
||||
// Handle new template creation vs update
|
||||
if (templateData["ID"]! == "" || templateData["ID"]! == "-1") {
|
||||
// Create new template
|
||||
templateData.remove("ID");
|
||||
id = await dbHelper.addTemplate(templateData);
|
||||
} else {
|
||||
// Update existing template
|
||||
await dbHelper.updateTemplate(templateData);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user