added sent and id column again for add_cam_main
id checks if entry already exists. sent says if the entry is already sent to the db
This commit is contained in:
@@ -1,21 +1,38 @@
|
||||
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';
|
||||
|
||||
class SaveMainEntryMethod {
|
||||
static void saveEntry(
|
||||
{required Map<String, String> entryData,
|
||||
required bool isTemplate,
|
||||
bool sent = false}) async {
|
||||
var placeDB = PlaceDBHelper();
|
||||
static void saveEntry({
|
||||
required Map<String, String> entryData,
|
||||
required bool isTemplate,
|
||||
required DatabasesEnum dbType,
|
||||
bool sent = false,
|
||||
}) async {
|
||||
|
||||
IDb? placeDB;
|
||||
|
||||
if (dbType == DatabasesEnum.place) {
|
||||
placeDB = PlaceDBHelper();
|
||||
} else if (dbType == DatabasesEnum.excursion) {
|
||||
placeDB = ExcursionDBHelper();
|
||||
}
|
||||
|
||||
int entryId;
|
||||
|
||||
// Get the ID of the newly added or updated place
|
||||
int newPlaceId = await placeDB.addMainEntry(entryData);
|
||||
if (entryData["ID"] == "") {
|
||||
entryData.remove("ID");
|
||||
entryId = await placeDB!.addMainEntry(entryData);
|
||||
} else {
|
||||
entryId = await placeDB!.updateMainEntry(entryData);
|
||||
}
|
||||
|
||||
if (sent == true) {
|
||||
placeDB.updateSent(newPlaceId); // Update 'Sent' using the correct ID
|
||||
placeDB.updateSent(entryId); // Update 'Sent' using the correct ID
|
||||
}
|
||||
|
||||
if (isTemplate) {
|
||||
await placeDB.deleteTemplateById(entryData["CID"]!);
|
||||
}
|
||||
await placeDB.deleteTemplateById(entryData["CID"]!);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user