|
|
|
@ -101,10 +101,62 @@ namespace Justice.Views |
|
|
|
|
await DisplayAlert("Error", "Please fill in all required fields.", "OK"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
await SetLoadingStateAsync(true); //show loader |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
var (latitude, longitude, address) = await GeolocationHelper.GetLocationAsync(); |
|
|
|
|
var report = new IncidentReport |
|
|
|
|
{ |
|
|
|
|
ReporterName = ReporterNameEntry.Text.Trim(), |
|
|
|
|
IncidentType = IncidentTypePicker.SelectedItem.ToString(), |
|
|
|
|
Description = DescriptionEditor.Text.Trim(), |
|
|
|
|
Latitude = latitude, |
|
|
|
|
Longitude = longitude, |
|
|
|
|
Address = address, |
|
|
|
|
DateTime = DateTime.Now, |
|
|
|
|
AttachmentPath = _selectedAttachmentPath |
|
|
|
|
}; |
|
|
|
|
//save report to database |
|
|
|
|
await _databaseHelper.InsertAsync(report); |
|
|
|
|
// get nearby authorities based on incident location |
|
|
|
|
var authorityService = new AuthorityService(); |
|
|
|
|
var nearbyAuthorities = authorityService.GetNearByAuthorities(report.Latitude, report.Longitude); |
|
|
|
|
// Prepare the email content |
|
|
|
|
string emailBody = $"Incident Report:\n\n" + |
|
|
|
|
$"Name: {report.ReporterName}\n" + |
|
|
|
|
$"Type: {report.IncidentType}\n" + |
|
|
|
|
$"Description: {report.Description}\n" + |
|
|
|
|
$"Latitude: {report.Latitude}\n" + |
|
|
|
|
$"Longitude: {report.Longitude}\n" + |
|
|
|
|
$"Location: {report.Address}\n" + |
|
|
|
|
$"Date/Time: {report.DateTime}"; |
|
|
|
|
|
|
|
|
|
// Send email to each nearby authority |
|
|
|
|
foreach (var authority in nearbyAuthorities) |
|
|
|
|
{ |
|
|
|
|
bool emailSent = await _emailService.SendEmailWithAttachmentAsync(authority.Email, "Incident Report", emailBody, _selectedAttachmentPath); |
|
|
|
|
|
|
|
|
|
var (latitude, longitude, address) = await GeolocationHelper.GetLocationAsync(); |
|
|
|
|
if (emailSent) |
|
|
|
|
{ |
|
|
|
|
Console.WriteLine($"Email sent to: {authority.Name}"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var report = new IncidentReport |
|
|
|
|
await DisplayAlert("Success", "Incident report submitted and email alert sent to nearby authorities.", "OK"); |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
await DisplayAlert("Error", $"Failed to submit report:{ex.Message}", "OK"); |
|
|
|
|
} |
|
|
|
|
finally |
|
|
|
|
{ |
|
|
|
|
await SetLoadingStateAsync(false); //hide loader |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// var (latitude, longitude, address) = await GeolocationHelper.GetLocationAsync(); |
|
|
|
|
|
|
|
|
|
/* var report = new IncidentReport |
|
|
|
|
{ |
|
|
|
|
ReporterName = ReporterNameEntry.Text.Trim(), |
|
|
|
|
IncidentType = IncidentTypePicker.SelectedItem.ToString(), |
|
|
|
@ -119,7 +171,7 @@ namespace Justice.Views |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
// Save the report to the database |
|
|
|
|
await SetLoadingStateAsync(true); |
|
|
|
|
|
|
|
|
|
await _databaseHelper.InsertAsync(report); |
|
|
|
|
|
|
|
|
|
// Get the recipient email based on the incident type |
|
|
|
@ -155,6 +207,7 @@ namespace Justice.Views |
|
|
|
|
{ |
|
|
|
|
await SetLoadingStateAsync(false); |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|