Auth-Attachment

main
unknown 6 months ago
parent 4108506fc5
commit afaf36ba01
  1. 4
      AppShell.xaml
  2. 4
      AppShell.xaml.cs
  3. 4
      Helpers/DatabaseHelper.cs
  4. 2
      Helpers/EmailService.cs
  5. 36
      Helpers/GeoHelper.cs
  6. 9
      Justice.csproj
  7. 9
      Justice.csproj.user
  8. 1
      Models/Authority.cs
  9. 5
      Models/IncidentReport.cs
  10. BIN
      Resources/Images/logo.png
  11. 4
      Services/AuthorityService.cs
  12. 37
      Views/AuthorityReportsPage.xaml
  13. 93
      Views/AuthorityReportsPage.xaml.cs
  14. 7
      Views/DashboardPage.xaml
  15. 2
      Views/DashboardPage.xaml.cs
  16. 26
      Views/EndUserReportsPage.xaml
  17. 43
      Views/EndUserReportsPage.xaml.cs
  18. 1
      Views/IncidentReportPage.xaml.cs
  19. 2
      Views/LoginPage.xaml.cs
  20. 33
      Views/ViewReportsPage.xaml
  21. 102
      Views/ViewReportsPage.xaml.cs

@ -9,8 +9,10 @@
<ShellContent Title="Login" ContentTemplate="{DataTemplate views:LoginPage}" Route="LoginPage" /> <ShellContent Title="Login" ContentTemplate="{DataTemplate views:LoginPage}" Route="LoginPage" />
<ShellContent Title="Dashboard" ContentTemplate="{DataTemplate views:DashboardPage}" Route="DashboardPage" /> <ShellContent Title="Dashboard" ContentTemplate="{DataTemplate views:DashboardPage}" Route="DashboardPage" />
<ShellContent Title="View Reports" ContentTemplate="{DataTemplate views:ViewReportsPage}" Route="ViewReportsPage" />
<ShellContent Title="Register" ContentTemplate="{DataTemplate views:RegistrationPage}" Route="RegistrationPage" /> <ShellContent Title="Register" ContentTemplate="{DataTemplate views:RegistrationPage}" Route="RegistrationPage" />
<ShellContent Title="My Reports" ContentTemplate="{DataTemplate views:EndUserReportsPage}" Route="EndUserReportsPage" />
<ShellContent Title="Authority Reports" ContentTemplate="{DataTemplate views:AuthorityReportsPage}" Route="AuthorityReportsPage" />
<MenuItem Text="Logout" Command="{Binding LogoutCommand}" /> <MenuItem Text="Logout" Command="{Binding LogoutCommand}" />
</Shell> </Shell>

@ -11,7 +11,7 @@ namespace Justice
Routing.RegisterRoute("LoginPage", typeof(Views.LoginPage)); Routing.RegisterRoute("LoginPage", typeof(Views.LoginPage));
Routing.RegisterRoute("DashboardPage", typeof(Views.DashboardPage)); Routing.RegisterRoute("DashboardPage", typeof(Views.DashboardPage));
Routing.RegisterRoute("ViewReportsPage", typeof(Views.ViewReportsPage)); Routing.RegisterRoute("ViewReportsPage", typeof(Views.EndUserReportsPage));
LogoutCommand = new Command(async () => LogoutCommand = new Command(async () =>
{ {
@ -29,7 +29,7 @@ namespace Justice
base.OnNavigating(args); base.OnNavigating(args);
// Check if user is authenticated // Check if user is authenticated
if (!AuthHelper.IsLoggedIn && args.Target.Location.OriginalString.Contains("ViewReportsPage") || !AuthHelper.IsLoggedIn && args.Target.Location.OriginalString.Contains("DashboardPage")) if (!AuthHelper.IsLoggedIn && args.Target.Location.OriginalString.Contains("EndUserReportPage") || !AuthHelper.IsLoggedIn && args.Target.Location.OriginalString.Contains("DashboardPage") || !AuthHelper.IsLoggedIn && args.Target.Location.OriginalString.Contains("AuthorityReportsPage"))
{ {
args.Cancel(); // Prevent navigation args.Cancel(); // Prevent navigation
await Shell.Current.GoToAsync("//LoginPage"); await Shell.Current.GoToAsync("//LoginPage");

@ -36,6 +36,10 @@ namespace Justice.Helpers
{ {
return await _database.DeleteAsync(item); return await _database.DeleteAsync(item);
} }
public async Task<int> UpdateAsync<T>(T item) where T : new()
{
return await _database.UpdateAsync(item);
}
public async Task<T> FindAsync<T>(string query, params object[] args) where T : new() public async Task<T> FindAsync<T>(string query, params object[] args) where T : new()
{ {
return await _database.FindWithQueryAsync<T>(query, args); return await _database.FindWithQueryAsync<T>(query, args);

@ -22,7 +22,7 @@ namespace Justice.Services
{ {
_incidentTypeToEmail = new Dictionary<string, string> _incidentTypeToEmail = new Dictionary<string, string>
{ {
{ "Accident", "amreitsyanf@gmail.com" }, { "Accident", "ambulancemaiti@gmail.com" },
{ "Crime", "crime-authority@example.com" }, { "Crime", "crime-authority@example.com" },
{ "Fire", "fire-department@example.com" }, { "Fire", "fire-department@example.com" },
{ "Other", "general-authority@example.com" } { "Other", "general-authority@example.com" }

@ -1,30 +1,28 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Justice.Helpers namespace Justice.Helpers
{ {
public class GeoHelper public static class GeoHelper
{ {
public static double CalculateDistance(double latitude1, double longitude1, double latitude2, double longitude2) public static double CalculateDistance(double lat1, double lon1, double lat2, double lon2)
{ {
double radianLat1 = Math.PI * latitude1 / 100; const double EarthRadiusKm = 6371;
double radianLat2 = Math.PI * latitude2 / 100;
double radianLong1 = Math.PI * longitude1 / 100;
double radianLong2 = Math.PI * longitude2 / 100;
double dLong = radianLong2 - radianLong1; double dLat = DegreesToRadians(lat2 - lat1);
double dLat = radianLat2 - radianLat1; double dLon = DegreesToRadians(lon2 - lon1);
double a = Math.Pow(Math.Sin(dLat / 2), 2) +
Math.Cos(radianLat1) * Math.Cos(radianLat2) *
Math.Pow(Math.Sin(dLong / 2),2);
double c = 2 * Math.Asin(Math.Sqrt(a));
const double radius = 6371; //radius of earth in kilometer
double distance = radius * c;
return distance; double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
Math.Cos(DegreesToRadians(lat1)) * Math.Cos(DegreesToRadians(lat2)) *
Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
return EarthRadiusKm * c;
}
private static double DegreesToRadians(double degrees)
{
return degrees * Math.PI / 180;
} }
} }
} }

@ -85,12 +85,18 @@
<MauiXaml Update="Views\AuthorityDashboardPage.xaml"> <MauiXaml Update="Views\AuthorityDashboardPage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Views\AuthorityReportsPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\DashboardPage.xaml"> <MauiXaml Update="Views\DashboardPage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Views\EmergencyContactsPage.xaml"> <MauiXaml Update="Views\EmergencyContactsPage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Views\EndUserReportsPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Views\HelplinePage.xaml"> <MauiXaml Update="Views\HelplinePage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
@ -109,9 +115,6 @@
<MauiXaml Update="Views\SosPage.xaml"> <MauiXaml Update="Views\SosPage.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Views\ViewReportsPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup> </ItemGroup>
</Project> </Project>

@ -17,12 +17,18 @@
<MauiXaml Update="Views\AuthorityDashboardPage.xaml"> <MauiXaml Update="Views\AuthorityDashboardPage.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Views\AuthorityReportsPage.xaml">
<SubType>Designer</SubType>
</MauiXaml>
<MauiXaml Update="Views\DashboardPage.xaml"> <MauiXaml Update="Views\DashboardPage.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Views\EmergencyContactsPage.xaml"> <MauiXaml Update="Views\EmergencyContactsPage.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Views\EndUserReportsPage.xaml">
<SubType>Designer</SubType>
</MauiXaml>
<MauiXaml Update="Views\HelplinePage.xaml"> <MauiXaml Update="Views\HelplinePage.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</MauiXaml> </MauiXaml>
@ -41,9 +47,6 @@
<MauiXaml Update="Views\SosPage.xaml"> <MauiXaml Update="Views\SosPage.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</MauiXaml> </MauiXaml>
<MauiXaml Update="Views\ViewReportsPage.xaml">
<SubType>Designer</SubType>
</MauiXaml>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="App.xaml"> <None Update="App.xaml">

@ -13,5 +13,6 @@ namespace Justice.Models
public double Latitude { get; set; } public double Latitude { get; set; }
public double Longitude { get; set; } public double Longitude { get; set; }
public string AuthorityType { get; set; } public string AuthorityType { get; set; }
public string ResponsibleFor { get; set; }
} }
} }

@ -1,4 +1,5 @@
using SQLite; using Org.BouncyCastle.Bcpg;
using SQLite;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -19,5 +20,7 @@ namespace Justice.Models
public string Address { get; set; } public string Address { get; set; }
public DateTime DateTime { get; set; } public DateTime DateTime { get; set; }
public string AttachmentPath { get; set; } public string AttachmentPath { get; set; }
public string Status { get; set; }
public string AssignedAuthority { get; set; }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 KiB

@ -16,8 +16,10 @@ namespace Justice.Services
new Authority { Name = "Police", Email = "amritsyangtan1@gmail.com", Latitude = 47.7008, Longitude = 60.3000, AuthorityType = "Accident" }, new Authority { Name = "Police", Email = "amritsyangtan1@gmail.com", Latitude = 47.7008, Longitude = 60.3000, AuthorityType = "Accident" },
new Authority { Name = "Police", Email = "amreitsyanf@gmail.com", Latitude = 27.7008, Longitude = 85.3000, AuthorityType = "Accident" }, new Authority { Name = "Police", Email = "amreitsyanf@gmail.com", Latitude = 27.7008, Longitude = 85.3000, AuthorityType = "Accident" },
new Authority { Name = "Fire Department", Email = "amAritsyangtan1@gmail.com", Latitude = 27.7110, Longitude = 85.2915, AuthorityType = "Fire" }, new Authority { Name = "Fire Department", Email = "amAritsyangtan1@gmail.com", Latitude = 27.7110, Longitude = 85.2915, AuthorityType = "Fire" },
new Authority { Name = "Crime", Email = "amritsyangtan1@gmail.com", Latitude = 47.7110, Longitude = 90.2915, AuthorityType = "Police" },
new Authority { Name = "Crime", Email = "amreitsyanf@gmail.com", Latitude = 30.7110, Longitude = 80.2915, AuthorityType = "Police" },
new Authority { Name = "Ambulance", Email = "ambulance@example.com", Latitude = 27.7052, Longitude = 85.3092, AuthorityType = "Ambulance" } new Authority { Name = "Ambulance", Email = "ambulance@example.com", Latitude = 27.7052, Longitude = 85.3092, AuthorityType = "Ambulance" }
}; };
public List<Authority> GetNearByAuthorities(double incidentLatitude, double incidentLongitude, double radiusKm = 10) public List<Authority> GetNearByAuthorities(double incidentLatitude, double incidentLongitude, double radiusKm = 10)
{ {
List<Authority> nearbyAuthorities = new List<Authority>(); List<Authority> nearbyAuthorities = new List<Authority>();

@ -0,0 +1,37 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Justice.Views.AuthorityReportsPage"
Title="Authority Reports">
<StackLayout Padding="20">
<Label Text="Submitted Reports" FontSize="Large" HorizontalOptions="Center" />
<!-- List of Reports -->
<ListView x:Name="ReportsListView" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="10">
<Label Text="{Binding IncidentType}" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Address}" FontSize="Small" TextColor="Gray" />
<Label Text="{Binding DateTime, StringFormat='Submitted on: {0:MMM dd, yyyy HH:mm}'}"
FontSize="Small" />
<Label Text="{Binding Description}" FontSize="Small" />
<!-- Attachment Section -->
<Button Text="View Attachment"
IsVisible="{Binding AttachmentPath, Converter={StaticResource NullToVisibilityConverter}}"
Clicked="OnViewAttachmentClicked"
CommandParameter="{Binding .}" CornerRadius="80" Margin="5"/>
<!-- Update Status Button -->
<Button Text="Mark as Resolved"
Clicked="OnUpdateStatusClicked"
CommandParameter="{Binding .}" CornerRadius="80" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>

@ -0,0 +1,93 @@
using Justice.Helpers;
using Justice.Models;
using System.Collections.ObjectModel;
using Justice.Services;
namespace Justice.Views
{
public partial class AuthorityReportsPage : ContentPage
{
private readonly DatabaseHelper _dbHelper;
public ObservableCollection<IncidentReport> Reports { get; set; }
public AuthorityReportsPage()
{
InitializeComponent();
_dbHelper = new DatabaseHelper();
Reports = new ObservableCollection<IncidentReport>();
ReportsListView.ItemsSource = Reports;
}
protected override async void OnAppearing()
{
base.OnAppearing();
await LoadReportsAsync();
}
private async Task LoadReportsAsync()
{
try
{
Reports.Clear();
var reportsFromDb = await _dbHelper.GetAllAsync<IncidentReport>();
foreach (var report in reportsFromDb)
{
Reports.Add(report);
}
}
catch (Exception ex)
{
await DisplayAlert("Error", $"Failed to load reports: {ex.Message}", "OK");
}
}
private async void OnUpdateStatusClicked(object sender, EventArgs e)
{
var button = sender as Button;
if (button?.CommandParameter is IncidentReport selectedReport)
{
selectedReport.Status = "Resolved";
try
{
await _dbHelper.UpdateAsync(selectedReport);
await DisplayAlert("Success", "Status updated to Resolved.", "OK");
// Push notification to end user (dummy logic)
await DisplayAlert("Notification", $"Notification sent to {selectedReport.ReporterName}.", "OK");
await LoadReportsAsync();
}
catch (Exception ex)
{
await DisplayAlert("Error", $"Failed to update status: {ex.Message}", "OK");
}
}
}
private async void OnViewAttachmentClicked(object sender, EventArgs e)
{
var button = sender as Button;
if (button?.CommandParameter is IncidentReport selectedReport)
{
if (!string.IsNullOrEmpty(selectedReport.AttachmentPath))
{
try
{
await Launcher.OpenAsync(new OpenFileRequest
{
File = new ReadOnlyFile(selectedReport.AttachmentPath)
});
}
catch (Exception ex)
{
await DisplayAlert("Error", $"Failed to open attachment: {ex.Message}", "OK");
}
}
else
{
await DisplayAlert("Error", "No attachment found for this report.", "OK");
}
}
}
}
}

@ -141,13 +141,6 @@
</VerticalStackLayout> </VerticalStackLayout>
</Border> </Border>
</Grid> </Grid>
<Grid RowSpacing="15" ColumnSpacing="15" Padding="10">
<VerticalStackLayout>
<Border HorizontalOptions="Fill" HeightRequest="90">
<Label Text="hello" VerticalOptions="Center" HorizontalOptions="Center"></Label>
</Border>
</VerticalStackLayout>
</Grid>
</VerticalStackLayout> </VerticalStackLayout>
</ScrollView> </ScrollView>
</ContentPage> </ContentPage>

@ -24,7 +24,7 @@ public partial class DashboardPage : ContentPage
private void OnViewReportClicked(object sender, EventArgs e) private void OnViewReportClicked(object sender, EventArgs e)
{ {
Navigation.PushAsync(new ViewReportsPage()); Navigation.PushAsync(new EndUserReportsPage());
} }
private void OnIncidentReportClicked(object sender, EventArgs e) private void OnIncidentReportClicked(object sender, EventArgs e)
{ {

@ -0,0 +1,26 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Justice.Views.EndUserReportsPage"
Title="My Reports">
<StackLayout Padding="20">
<Label Text="My Submitted Reports" FontSize="Large" HorizontalOptions="Center" />
<!-- List of Submitted Reports -->
<ListView x:Name="ReportsListView" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="10">
<Label Text="{Binding IncidentType}" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Address}" FontSize="Small" TextColor="Gray" />
<Label Text="{Binding DateTime, StringFormat='Submitted on: {0:MMM dd, yyyy HH:mm}'}" FontSize="Small" />
<Label Text="{Binding Description}" FontSize="Small" />
<Label Text="{Binding Status}" FontSize="Small" FontAttributes="Bold" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>

@ -0,0 +1,43 @@
using Justice.Helpers;
using Justice.Models;
using System.Collections.ObjectModel;
namespace Justice.Views
{
public partial class EndUserReportsPage : ContentPage
{
private readonly DatabaseHelper _dbHelper;
public ObservableCollection<IncidentReport> Reports { get; set; }
public EndUserReportsPage()
{
InitializeComponent();
_dbHelper = new DatabaseHelper();
Reports = new ObservableCollection<IncidentReport>();
ReportsListView.ItemsSource = Reports;
}
protected override async void OnAppearing()
{
base.OnAppearing();
await LoadReportsAsync();
}
private async Task LoadReportsAsync()
{
try
{
Reports.Clear();
var reportsFromDb = await _dbHelper.GetAllAsync<IncidentReport>();
foreach (var report in reportsFromDb)
{
Reports.Add(report);
}
}
catch (Exception ex)
{
await DisplayAlert("Error", $"Failed to load reports: {ex.Message}", "OK");
}
}
}
}

@ -135,7 +135,6 @@ namespace Justice.Views
foreach (var authority in nearbyAuthorities) foreach (var authority in nearbyAuthorities)
{ {
bool emailSent = await _emailService.SendEmailWithAttachmentAsync(authority.Email, "Incident Report", emailBody, _selectedAttachmentPath); bool emailSent = await _emailService.SendEmailWithAttachmentAsync(authority.Email, "Incident Report", emailBody, _selectedAttachmentPath);
if (emailSent) if (emailSent)
{ {
Console.WriteLine($"Email sent to: {authority.Name}"); Console.WriteLine($"Email sent to: {authority.Name}");

@ -49,7 +49,7 @@ namespace Justice.Views
else if (enteredUsername == authvalidUsername && enteredPassword == authvalidPassword && selectedRole == "Authority User") else if (enteredUsername == authvalidUsername && enteredPassword == authvalidPassword && selectedRole == "Authority User")
{ {
AuthHelper.Login("AuthorityUser"); AuthHelper.Login("AuthorityUser");
await Shell.Current.GoToAsync("//ViewReportsPage"); await Shell.Current.GoToAsync("//AuthorityReportsPage");
} }
else else
{ {

@ -1,33 +0,0 @@
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Justice.Views.ViewReportsPage"
Title="View Reports">
<StackLayout Padding="20">
<Label Text="Submitted Reports" FontSize="Large" HorizontalOptions="Center" />
<!-- List of Reports -->
<ListView x:Name="ReportsListView"
HasUnevenRows="True"
ItemSelected="OnReportSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="10" Orientation="Horizontal">
<StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="FillAndExpand">
<Label Text="{Binding IncidentType}" FontSize="Medium" FontAttributes="Bold" />
<Label Text="{Binding Address}" FontSize="Small" TextColor="Gray" />
<Label Text="{Binding DateTime, StringFormat='Submitted on: {0:MMM dd, yyyy HH:mm}'}"
FontSize="Small" />
<Label Text="{Binding Description}" FontSize="Small" />
</StackLayout>
<Button x:Name="DeleteName" Text="Delete"
Clicked="OnDeleteReportClicked"
CommandParameter="{Binding .}" HeightRequest="10" IsVisible="True"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>

@ -1,102 +0,0 @@
using Justice.Helpers;
using Justice.Models;
using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using Justice.Services;
namespace Justice.Views
{
public partial class ViewReportsPage : ContentPage
{
private readonly DatabaseHelper _databaseHelper;
public ObservableCollection<IncidentReport> Reports { get; set; }
public ViewReportsPage()
{
InitializeComponent();
_databaseHelper = new DatabaseHelper();
Reports = new ObservableCollection<IncidentReport>();
ReportsListView.ItemsSource = Reports;
}
protected override async void OnAppearing()
{
base.OnAppearing();
await LoadReportsAsync();
}
private async Task LoadReportsAsync()
{
try
{
var reportsFromDb = await _databaseHelper.GetAllAsync<IncidentReport>();
Reports.Clear();
foreach (var report in reportsFromDb)
{
Reports.Add(report);
}
}
catch (Exception ex)
{
await DisplayAlert("Error", $"Failed to load reports: {ex.Message}", "OK");
}
}
private async void OnReportSelected(object sender, SelectedItemChangedEventArgs e)
{
if (e.SelectedItem is IncidentReport selectedReport)
{
await DisplayAlert("Report Details",
$"Type: {selectedReport.IncidentType}\n" +
$"Description: {selectedReport.Description}\n" +
$"Address: {selectedReport.Address}\n" +
$"Submitted on: {selectedReport.DateTime:MMM dd, yyyy HH:mm}\n" +
$"Attachment: {(string.IsNullOrWhiteSpace(selectedReport.AttachmentPath) ? "None" : "Attached")}",
"OK");
// Deselect the item
ReportsListView.SelectedItem = null;
}
}
private async void OnDeleteReportClicked(object sender, EventArgs e)
{
// Get the button's binding context
if (sender is Button deleteButton && deleteButton.CommandParameter is IncidentReport reportToDelete)
{
bool confirm = await DisplayAlert("Delete Report", "Are you sure you want to delete this report?", "Yes", "No");
if (confirm)
{
try
{
// Delete the report from the database
await _databaseHelper.DeleteAsync(reportToDelete);
// Remove the report from the ObservableCollection
Reports.Remove(reportToDelete);
await DisplayAlert("Success", "Report deleted successfully.", "OK");
}
catch (Exception ex)
{
await DisplayAlert("Error", $"Failed to delete report: {ex.Message}", "OK");
}
}
}
}
private async void OnLogoutClicked(object sender, EventArgs e)
{
bool confirm = await DisplayAlert("Logout", "Are you sure you want to log out?", "Yes", "No");
if (confirm)
{
// Redirect to Login Page
await Shell.Current.GoToAsync("//LoginPage");
}
}
private void MenuItem_Clicked(object sender, EventArgs e)
{
}
}
}
Loading…
Cancel
Save