// Adding new attachment to incident public void addAttachmentToIncident(Attachment attachment, Incident incident) { db = dbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("Incident_Id", incident.getId()); values.put("Attachment_Id", attachment.getId()); // updating row db.insert(Constants.TABLE_INCIDENT_ATTACHMENT, null, values); }
// Add notify contact to incident public void addNotifyContactToIncident(Incident anIncident, Contact aContact) { db = dbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("Incident_Id", anIncident.getId()); values.put("Contact_Id", aContact.getId()); // updating row db.insert(Constants.TABLE_INCIDENT_NOTIFY_CONTACT, null, values); }
// Deleting all attachments for an Incident public void deleteAllAttachmentsForIncident(Incident incident) { db = dbHelper.getWritableDatabase(); if (incident.getAttachments().size() > 0) { for (Attachment anAttachment : incident.getAttachments()) { attachment_dao.deleteSingleAttachment(anAttachment); } } db.delete( Constants.TABLE_INCIDENT_ATTACHMENT, "Incident_Id" + " = ?", new String[] {String.valueOf(incident.getId())}); }
// Updating a Incident public void updateIncident(Incident incident) { db = dbHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("IncidentTypeId", incident.getIncidentType().getId()); values.put("CreatedByContactId", incident.getCreatedBy().getId()); values.put("IncidentDate", DateTimeHelper.formatToIS08601(incident.getIncidentDate())); values.put("Description", incident.getDescription()); values.put("InitialAction", incident.getInitialAction()); values.put("Reportable", incident.getReportable()); // updating row db.update( Constants.TABLE_INCIDENT, values, "Id=?", new String[] {String.valueOf(incident.getId())}); removeAllNotifyContactsFromIncident(incident.getId()); if (incident.getNotifyContacts().size() > 0) { for (Contact c : incident.getNotifyContacts()) { addNotifyContactToIncident(incident, c); } } }