diff --git a/App.xaml.cs b/App.xaml.cs index 0a1e082..2a18fbb 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -16,7 +16,8 @@ namespace Justice try { var dbHelper = new DatabaseHelper(); - await dbHelper.InitializeAsync(); // Asynchronously create the EmergencyContact table + await dbHelper.InitializeAsync(); + await dbHelper.InitializeAsync();// Asynchronously create the EmergencyContact table } catch (Exception ex) { diff --git a/Helpers/EmailService.cs b/Helpers/EmailService.cs index 0d82c30..496d631 100644 --- a/Helpers/EmailService.cs +++ b/Helpers/EmailService.cs @@ -1,22 +1,25 @@ using System; using System.Collections.Generic; +using System.IO; using System.Net; using System.Net.Mail; using System.Threading.Tasks; -namespace ChildGuard.Services +namespace Justice.Services { + public class EmailService { private readonly string _smtpServer = "smtp.gmail.com"; private readonly int _smtpPort = 587; - private readonly string _senderEmail = "amritsyangtan1@gmail.com"; // Replace with your email - private readonly string _senderPassword = "bdcx ycpy cbrr szpm"; // Replace with your app password + private readonly string _senderEmail = "amritsyangtan1@gmail.com"; + private readonly string _senderPassword = "bdcx ycpy cbrr szpm"; + + // Map incident types to recipient emails private readonly Dictionary _incidentTypeToEmail; public EmailService() { - // Map incident types to authority emails _incidentTypeToEmail = new Dictionary { { "Accident", "amreitsyanf@gmail.com" }, @@ -27,13 +30,19 @@ namespace ChildGuard.Services } /// - /// Sends an email using SMTP. + /// Gets the recipient email address based on the incident type. + /// + /// The type of the incident. + /// The email address of the recipient. + public string GetRecipientEmail(string incidentType) + { + return _incidentTypeToEmail.TryGetValue(incidentType, out var email) ? email : "amreitsyanf@gmail.com"; + } + + /// + /// Sends an email with an optional attachment. /// - /// Recipient's email address. - /// Email subject. - /// Email body. - /// True if successful, otherwise false. - public async Task SendEmailAsync(string recipientEmail, string subject, string body) + public async Task SendEmailWithAttachmentAsync(string recipientEmail, string subject, string body, string attachmentPath) { try { @@ -52,6 +61,11 @@ namespace ChildGuard.Services mailMessage.To.Add(recipientEmail); + if (!string.IsNullOrWhiteSpace(attachmentPath) && File.Exists(attachmentPath)) + { + mailMessage.Attachments.Add(new Attachment(attachmentPath)); + } + await smtpClient.SendMailAsync(mailMessage); } @@ -64,15 +78,5 @@ namespace ChildGuard.Services return false; } } - - /// - /// Gets the recipient email based on the incident type. - /// - /// Incident type. - /// Recipient email address. - public string GetRecipientEmail(string incidentType) - { - return _incidentTypeToEmail.TryGetValue(incidentType, out var email) ? email : "default-authority@example.com"; - } } } diff --git a/Justice.csproj b/Justice.csproj index 19ceb4e..e36fb25 100644 --- a/Justice.csproj +++ b/Justice.csproj @@ -60,6 +60,7 @@ + diff --git a/Justice.csproj.user b/Justice.csproj.user index 7fa239b..3743e56 100644 --- a/Justice.csproj.user +++ b/Justice.csproj.user @@ -3,8 +3,8 @@ False net9.0-android - Medium Phone API 35 (Android 15.0 - API 35) - Emulator + Samsung SM-M325F (Android 13.0 - API 33) + PhysicalDevice Medium_Phone_API_35 diff --git a/Views/IncidentReportPage.xaml b/Views/IncidentReportPage.xaml index dea2739..35187f0 100644 --- a/Views/IncidentReportPage.xaml +++ b/Views/IncidentReportPage.xaml @@ -5,11 +5,9 @@ -