FÉLKÉSZ
This commit is contained in:
@@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WorkFlowCheck.Common.DTO
|
||||||
|
{
|
||||||
|
public class MobileUserDTO
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? UserName { get; set; }
|
||||||
|
public string? FirstName { get; set; }
|
||||||
|
public string? LastName { get; set; }
|
||||||
|
public string? Email { get; set; }
|
||||||
|
public string? PhoneNumber { get; set; }
|
||||||
|
public bool NFCActive { get; set; }
|
||||||
|
public string NFCCode { get; set; } = null!;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ namespace WorkFlowCheck.MAUI.DataLayer
|
|||||||
public DbSet<CheckPoint> CheckPoints { get; set; }
|
public DbSet<CheckPoint> CheckPoints { get; set; }
|
||||||
public DbSet<Equipment> Equipments { get; set; }
|
public DbSet<Equipment> Equipments { get; set; }
|
||||||
public DbSet<Location> Locations { get; set; }
|
public DbSet<Location> Locations { get; set; }
|
||||||
|
public DbSet<MobileUser> MobileUsers { get; set; }
|
||||||
|
|
||||||
public AppDbContext()
|
public AppDbContext()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WorkFlowCheck.MAUI.DataLayer.Entities
|
||||||
|
{
|
||||||
|
public class MobileUser
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? UserName { get; set; }
|
||||||
|
|
||||||
|
public string? FirstName { get; set; }
|
||||||
|
public string? LastName { get; set; }
|
||||||
|
public string? Email { get; set; }
|
||||||
|
public string? PhoneNumber { get; set; }
|
||||||
|
public bool NFCActive { get; set; }
|
||||||
|
public string NFCCode { get; set; } = null!;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,26 +7,33 @@
|
|||||||
<Frame BorderColor="Gray" Padding="5" Margin="1" HasShadow="True">
|
<Frame BorderColor="Gray" Padding="5" Margin="1" HasShadow="True">
|
||||||
<VerticalStackLayout Margin="10,10,10,0">
|
<VerticalStackLayout Margin="10,10,10,0">
|
||||||
<Button
|
<Button
|
||||||
x:Name="ButtonGetCheckPoints"
|
x:Name="ButtonGetCheckPoints"
|
||||||
Margin="0,0,0,10"
|
Margin="0,0,0,10"
|
||||||
Text="Ellenőrzési pontok"
|
Text="Ellenőrzési pontok"
|
||||||
SemanticProperties.Hint="Ellenőrzési pontok"
|
SemanticProperties.Hint="Ellenőrzési pontok"
|
||||||
Clicked="OnButtonGetCheckPoints"
|
Clicked="OnButtonGetCheckPoints"
|
||||||
HorizontalOptions="Fill" />
|
HorizontalOptions="Fill" />
|
||||||
<Button
|
<Button
|
||||||
x:Name="ButtonGetEquipments"
|
x:Name="ButtonGetEquipments"
|
||||||
Margin="0,0,0,10"
|
Margin="0,0,0,10"
|
||||||
Text="Berendezések"
|
Text="Berendezések"
|
||||||
SemanticProperties.Hint="Berendezések"
|
SemanticProperties.Hint="Berendezések"
|
||||||
Clicked="OnButtonGetCheckPoints"
|
Clicked="OnButtonGetEquipments"
|
||||||
HorizontalOptions="Fill" />
|
HorizontalOptions="Fill" />
|
||||||
<Button
|
<Button
|
||||||
x:Name="ButtonGetLocations"
|
x:Name="ButtonGetLocations"
|
||||||
Margin="0,0,0,10"
|
Margin="0,0,0,10"
|
||||||
Text="Lokációk"
|
Text="Lokációk"
|
||||||
SemanticProperties.Hint="Lokációk"
|
SemanticProperties.Hint="Lokációk"
|
||||||
Clicked="OnButtonGetCheckPoints"
|
Clicked="OnButtonGetLocations"
|
||||||
HorizontalOptions="Fill" />
|
HorizontalOptions="Fill" />
|
||||||
|
<Button
|
||||||
|
x:Name="ButtonGetUsers"
|
||||||
|
Margin="0,0,0,10"
|
||||||
|
Text="Felhasználók"
|
||||||
|
SemanticProperties.Hint="Felhasználók"
|
||||||
|
Clicked="OnButtonGetUsers"
|
||||||
|
HorizontalOptions="Fill" />
|
||||||
</VerticalStackLayout>
|
</VerticalStackLayout>
|
||||||
</Frame>
|
</Frame>
|
||||||
</VerticalStackLayout>
|
</VerticalStackLayout>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using WorkFlowCheck.Common.DTO;
|
using WorkFlowCheck.Common.DTO;
|
||||||
|
using WorkFlowCheck.MAUI.Pages.Security;
|
||||||
|
|
||||||
namespace WorkFlowCheck.MAUI.Pages.BaseStock;
|
namespace WorkFlowCheck.MAUI.Pages.BaseStock;
|
||||||
|
|
||||||
@@ -16,11 +17,18 @@ public partial class BaseStockPage : ContentPage
|
|||||||
}
|
}
|
||||||
private async void OnButtonGetEquipments(object sender, EventArgs e)
|
private async void OnButtonGetEquipments(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await Shell.Current.GoToAsync("//EquipmentsPage");
|
//await Shell.Current.GoToAsync("//EquipmentsPage");
|
||||||
|
await Navigation.PushAsync(new EquipmentsPage());
|
||||||
}
|
}
|
||||||
private async void OnButtonGetLocations(object sender, EventArgs e)
|
private async void OnButtonGetLocations(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
await Shell.Current.GoToAsync("//LocationsPage");
|
//await Shell.Current.GoToAsync("//LocationsPage");
|
||||||
|
await Navigation.PushAsync(new LocationsPage());
|
||||||
|
}
|
||||||
|
private async void OnButtonGetUsers(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
//await Shell.Current.GoToAsync("//LocationsPage");
|
||||||
|
await Navigation.PushAsync(new UsersPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnBackButtonPressed()
|
protected override bool OnBackButtonPressed()
|
||||||
|
|||||||
@@ -3,36 +3,46 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
x:Class="WorkFlowCheck.MAUI.Pages.BaseStock.CheckPointsPage"
|
x:Class="WorkFlowCheck.MAUI.Pages.BaseStock.CheckPointsPage"
|
||||||
Title="Ellenőrzési pontok">
|
Title="Ellenőrzési pontok">
|
||||||
<StackLayout>
|
<Grid>
|
||||||
<Label x:Name="progressLabel" Text="Folyamatjelző" FontSize="Medium" HorizontalOptions="Center" />
|
<!-- Fő tartalom -->
|
||||||
<ProgressBar x:Name="progressBar" WidthRequest="300" HeightRequest="40" />
|
<StackLayout>
|
||||||
<Button
|
<Label x:Name="progressLabel" Text="Folyamatjelző" FontSize="Medium" HorizontalOptions="Center" />
|
||||||
x:Name="ButtonSync" Margin="5"
|
<ProgressBar x:Name="progressBar" WidthRequest="300" HeightRequest="40" />
|
||||||
Text="Adatok szinkronizálása"
|
<Button
|
||||||
SemanticProperties.Hint="Adatok szinkronizálása"
|
x:Name="ButtonSync" Margin="5"
|
||||||
Clicked="OnButtonSync"
|
Text="Adatok szinkronizálása"
|
||||||
HorizontalOptions="Fill" />
|
SemanticProperties.Hint="Adatok szinkronizálása"
|
||||||
<RefreshView x:Name="refreshView" Command="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}">
|
Clicked="OnButtonSync"
|
||||||
<CollectionView x:Name="CheckPointsList">
|
HorizontalOptions="Fill" />
|
||||||
<CollectionView.ItemTemplate>
|
<RefreshView x:Name="refreshView" Command="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}">
|
||||||
<DataTemplate>
|
<CollectionView x:Name="CheckPointsList">
|
||||||
<Frame BorderColor="Gray" Padding="10" Margin="5" HasShadow="True" BackgroundColor="WhiteSmoke">
|
<CollectionView.ItemTemplate>
|
||||||
<StackLayout>
|
<DataTemplate>
|
||||||
<Label Text="{Binding ShortName}" FontSize="16" FontAttributes="Bold" />
|
<Frame BorderColor="Gray" Padding="10" Margin="5" HasShadow="True" BackgroundColor="WhiteSmoke">
|
||||||
<Label Text="{Binding Code}" FontSize="14" />
|
<StackLayout>
|
||||||
<HorizontalStackLayout HorizontalOptions="End">
|
<Label Text="{Binding ShortName}" FontSize="16" FontAttributes="Bold" />
|
||||||
<Button Text="Edit" Margin="5,0,0,0"
|
<Label Text="{Binding Code}" FontSize="14" />
|
||||||
Command="{Binding BindingContext.EditCommand, Source={x:Reference CheckPointsList}}"
|
<HorizontalStackLayout HorizontalOptions="End">
|
||||||
CommandParameter="{Binding .}" />
|
<Button Text="Edit" Margin="5,0,0,0"
|
||||||
<Button Text="Pair" Margin="5,0,0,0"
|
Command="{Binding BindingContext.EditCommand, Source={x:Reference CheckPointsList}}"
|
||||||
Command="{Binding BindingContext.PairCommand, Source={x:Reference CheckPointsList}}"
|
CommandParameter="{Binding .}" />
|
||||||
CommandParameter="{Binding .}" />
|
<Button Text="Pair" Margin="5,0,0,0"
|
||||||
</HorizontalStackLayout>
|
Command="{Binding BindingContext.PairCommand, Source={x:Reference CheckPointsList}}"
|
||||||
</StackLayout>
|
CommandParameter="{Binding .}" />
|
||||||
</Frame>
|
</HorizontalStackLayout>
|
||||||
</DataTemplate>
|
</StackLayout>
|
||||||
</CollectionView.ItemTemplate>
|
</Frame>
|
||||||
</CollectionView>
|
</DataTemplate>
|
||||||
</RefreshView>
|
</CollectionView.ItemTemplate>
|
||||||
</StackLayout>
|
</CollectionView>
|
||||||
|
</RefreshView>
|
||||||
|
</StackLayout>
|
||||||
|
|
||||||
|
<!-- Betöltés közbeni ActivityIndicator -->
|
||||||
|
<Grid x:Name="loadingOverlay" BackgroundColor="#80000000" IsVisible="{Binding IsLoading}" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0, 0, 1, 1">
|
||||||
|
<ActivityIndicator IsRunning="{Binding IsLoading}" Color="White"
|
||||||
|
VerticalOptions="Center" HorizontalOptions="Center"
|
||||||
|
WidthRequest="50" HeightRequest="50"/>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
</ContentPage>
|
</ContentPage>
|
||||||
@@ -20,11 +20,20 @@ public partial class CheckPointsPage : ContentPage
|
|||||||
_baseStockService = MauiProgram.ServiceProvider.GetRequiredService<IBaseStockService>();
|
_baseStockService = MauiProgram.ServiceProvider.GetRequiredService<IBaseStockService>();
|
||||||
_syncService = MauiProgram.ServiceProvider.GetRequiredService<ISyncService>();
|
_syncService = MauiProgram.ServiceProvider.GetRequiredService<ISyncService>();
|
||||||
}
|
}
|
||||||
|
private bool _isLoading;
|
||||||
|
public bool IsLoading
|
||||||
|
{
|
||||||
|
get => _isLoading;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_isLoading = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
public ICommand RefreshCommand { get; set; }
|
public ICommand RefreshCommand { get; set; }
|
||||||
public ICommand EditCommand { get; set; }
|
public ICommand EditCommand { get; set; }
|
||||||
public ICommand PairCommand { get; set; }
|
public ICommand PairCommand { get; set; }
|
||||||
public bool IsRefreshing { get; set; }
|
|
||||||
|
|
||||||
protected override async void OnAppearing()
|
protected override async void OnAppearing()
|
||||||
{
|
{
|
||||||
@@ -39,15 +48,12 @@ public partial class CheckPointsPage : ContentPage
|
|||||||
}
|
}
|
||||||
private async Task LoadCheckPoints()
|
private async Task LoadCheckPoints()
|
||||||
{
|
{
|
||||||
IsRefreshing = true;
|
IsLoading = true;
|
||||||
//await _syncService.SyncDatas();
|
|
||||||
CheckPointsList.ItemsSource = await _baseStockService.GetAllCheckPoints();
|
CheckPointsList.ItemsSource = await _baseStockService.GetAllCheckPoints();
|
||||||
IsRefreshing = false;
|
IsLoading = false;
|
||||||
OnPropertyChanged(nameof(IsRefreshing));
|
|
||||||
}
|
}
|
||||||
private async void OnEditItem(CheckPointDTO checkPointDTO)
|
private async void OnEditItem(CheckPointDTO checkPointDTO)
|
||||||
{
|
{
|
||||||
// Navigálás a CheckPointEdit.xaml-ra, és átadjuk az editálni kívánt elemet
|
|
||||||
await Navigation.PushAsync(new CheckPointEditPage(checkPointDTO));
|
await Navigation.PushAsync(new CheckPointEditPage(checkPointDTO));
|
||||||
}
|
}
|
||||||
private async void OnPairItem(CheckPointDTO checkPointDTO)
|
private async void OnPairItem(CheckPointDTO checkPointDTO)
|
||||||
@@ -74,7 +80,7 @@ public partial class CheckPointsPage : ContentPage
|
|||||||
}
|
}
|
||||||
private async void OnButtonSync(object sender, EventArgs e)
|
private async void OnButtonSync(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
IsRefreshing = true;
|
IsLoading = true;
|
||||||
ButtonSync.IsEnabled = false;
|
ButtonSync.IsEnabled = false;
|
||||||
|
|
||||||
progressLabel.Text = "Szinkronizálás indítása...";
|
progressLabel.Text = "Szinkronizálás indítása...";
|
||||||
@@ -103,7 +109,7 @@ public partial class CheckPointsPage : ContentPage
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
ButtonSync.IsEnabled = true;
|
ButtonSync.IsEnabled = true;
|
||||||
IsRefreshing = false;
|
IsLoading = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
x:Class="WorkFlowCheck.MAUI.Pages.Security.UsersPage"
|
||||||
|
Title="Felhasználók">
|
||||||
|
<StackLayout>
|
||||||
|
<Label x:Name="progressLabel" Text="Folyamatjelző" FontSize="Medium" HorizontalOptions="Center" />
|
||||||
|
<ProgressBar x:Name="progressBar" WidthRequest="300" HeightRequest="40" />
|
||||||
|
<Button
|
||||||
|
x:Name="ButtonSync" Margin="5"
|
||||||
|
Text="Adatok szinkronizálása"
|
||||||
|
SemanticProperties.Hint="Adatok szinkronizálása"
|
||||||
|
Clicked="OnButtonSync"
|
||||||
|
HorizontalOptions="Fill" />
|
||||||
|
<RefreshView x:Name="refreshView" Command="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}">
|
||||||
|
<CollectionView x:Name="UsersList">
|
||||||
|
<CollectionView.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<Frame BorderColor="Gray" Padding="10" Margin="5" HasShadow="True" BackgroundColor="WhiteSmoke">
|
||||||
|
<StackLayout>
|
||||||
|
<Label Text="{Binding ShortName}" FontSize="16" FontAttributes="Bold" />
|
||||||
|
<Label Text="{Binding Code}" FontSize="14" />
|
||||||
|
<HorizontalStackLayout HorizontalOptions="End">
|
||||||
|
<Button Text="Edit" Margin="5,0,0,0"
|
||||||
|
Command="{Binding BindingContext.EditCommand, Source={x:Reference UsersList}}"
|
||||||
|
CommandParameter="{Binding .}" />
|
||||||
|
<Button Text="Pair" Margin="5,0,0,0"
|
||||||
|
Command="{Binding BindingContext.PairCommand, Source={x:Reference UsersList}}"
|
||||||
|
CommandParameter="{Binding .}" />
|
||||||
|
</HorizontalStackLayout>
|
||||||
|
</StackLayout>
|
||||||
|
</Frame>
|
||||||
|
</DataTemplate>
|
||||||
|
</CollectionView.ItemTemplate>
|
||||||
|
</CollectionView>
|
||||||
|
</RefreshView>
|
||||||
|
</StackLayout>
|
||||||
|
</ContentPage>
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
using System.Windows.Input;
|
||||||
|
using WorkFlowCheck.Common.DTO;
|
||||||
|
using WorkFlowCheck.MAUI.Services.Interfaces;
|
||||||
|
using WorkFlowCheck.MAUI.Pages.NFC;
|
||||||
|
|
||||||
|
namespace WorkFlowCheck.MAUI.Pages.Security;
|
||||||
|
|
||||||
|
public partial class UsersPage : ContentPage
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly IUserService _userService;
|
||||||
|
|
||||||
|
|
||||||
|
public UsersPage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_userService = MauiProgram.ServiceProvider.GetRequiredService<IUserService>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ICommand RefreshCommand { get; set; }
|
||||||
|
public ICommand PairCommand { get; set; }
|
||||||
|
public bool IsRefreshing { get; set; }
|
||||||
|
|
||||||
|
protected override async void OnAppearing()
|
||||||
|
{
|
||||||
|
base.OnAppearing();
|
||||||
|
RefreshCommand = new Command(async () => await LoadUsers());
|
||||||
|
PairCommand = new Command<UserDTO>(OnPairItem);
|
||||||
|
|
||||||
|
BindingContext = this;
|
||||||
|
await LoadUsers();
|
||||||
|
|
||||||
|
}
|
||||||
|
private async Task LoadUsers()
|
||||||
|
{
|
||||||
|
IsRefreshing = true;
|
||||||
|
//await _syncService.SyncDatas();
|
||||||
|
UsersList.ItemsSource = await _userService.GetAllUsers();
|
||||||
|
IsRefreshing = false;
|
||||||
|
OnPropertyChanged(nameof(IsRefreshing));
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OnPairItem(UserDTO UserDTO)
|
||||||
|
{
|
||||||
|
var UserCode = await NFCWaiter.ShowModalAsync();
|
||||||
|
if (!string.IsNullOrEmpty(UserCode))
|
||||||
|
{
|
||||||
|
if (Navigation.ModalStack.Count > 0)
|
||||||
|
{
|
||||||
|
await Navigation.PopModalAsync();
|
||||||
|
}
|
||||||
|
if (UserDTO != null)
|
||||||
|
{
|
||||||
|
UserDTO.Code = UserCode;
|
||||||
|
await _baseStockService.UpdateUser(UserDTO);
|
||||||
|
await LoadUsers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected override bool OnBackButtonPressed()
|
||||||
|
{
|
||||||
|
Shell.Current.GoToAsync("//BaseStockPage");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private async void OnButtonSync(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
IsRefreshing = true;
|
||||||
|
ButtonSync.IsEnabled = false;
|
||||||
|
|
||||||
|
progressLabel.Text = "Szinkronizálás indítása...";
|
||||||
|
progressBar.Progress = 0;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await _userService.SyncUsers_Up((percentage, infostring) =>
|
||||||
|
{
|
||||||
|
MainThread.BeginInvokeOnMainThread(() =>
|
||||||
|
{
|
||||||
|
progressBar.Progress = percentage / 100;
|
||||||
|
progressLabel.Text = $"{infostring}: {percentage:0.00}%";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
progressLabel.Text = "Szinkronizálás befejezve!";
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
progressLabel.Text = $"Hiba történt: {ex.Message}";
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ButtonSync.IsEnabled = true;
|
||||||
|
IsRefreshing = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,8 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using WorkFlowCheck.MAUI.DataLayer;
|
using WorkFlowCheck.MAUI.DataLayer;
|
||||||
using WorkFlowCheck.MAUI.Services.Interfaces;
|
using WorkFlowCheck.MAUI.Services.Interfaces;
|
||||||
|
using Android.Provider;
|
||||||
|
using Android.DeviceLock;
|
||||||
|
|
||||||
namespace WorkFlowCheck.MAUI.Services
|
namespace WorkFlowCheck.MAUI.Services
|
||||||
{
|
{
|
||||||
@@ -20,6 +22,7 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
public readonly AppDbContext _dbContext;
|
public readonly AppDbContext _dbContext;
|
||||||
public readonly IConfiguration _configuration;
|
public readonly IConfiguration _configuration;
|
||||||
public readonly IMapper _mapper;
|
public readonly IMapper _mapper;
|
||||||
|
private string _deviceId;
|
||||||
|
|
||||||
public BaseService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper)
|
public BaseService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper)
|
||||||
{
|
{
|
||||||
@@ -33,6 +36,7 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
|
|
||||||
var apiKey = configuration["ApiKey"];
|
var apiKey = configuration["ApiKey"];
|
||||||
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiKey);
|
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiKey);
|
||||||
|
_deviceId = GetDeviceId();
|
||||||
}
|
}
|
||||||
protected async Task PrepareAuthenticatedRequestAsync()
|
protected async Task PrepareAuthenticatedRequestAsync()
|
||||||
{
|
{
|
||||||
@@ -41,6 +45,20 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
if (!string.IsNullOrEmpty(jwtToken) && _httpClient != null)
|
if (!string.IsNullOrEmpty(jwtToken) && _httpClient != null)
|
||||||
{
|
{
|
||||||
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken);
|
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken);
|
||||||
|
_httpClient.DefaultRequestHeaders.Add("DeviceId", _deviceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected string GetDeviceId()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var context = Android.App.Application.Context;
|
||||||
|
return Settings.Secure.GetString(context.ContentResolver, Settings.Secure.AndroidId) ?? "NO_ANDROID_DEVICE";
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error retrieving device ID: {ex.Message}");
|
||||||
|
return "UnknownDevice";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces
|
|||||||
{
|
{
|
||||||
Task SyncDatas(Action<double, string> reportProgress);
|
Task SyncDatas(Action<double, string> reportProgress);
|
||||||
Task SyncCheckPoints_Down(Action<double, string> reportProgress);
|
Task SyncCheckPoints_Down(Action<double, string> reportProgress);
|
||||||
Task SyncCheckPoints_Up(Action<double, string> reportProgress);
|
Task<ApiResponseDTO<string>> SyncCheckPoints_Up(Action<double, string> reportProgress);
|
||||||
Task SyncLocations_Down(Action<double, string> reportProgress);
|
Task SyncLocations_Down(Action<double, string> reportProgress);
|
||||||
Task SyncEquipments_Down(Action<double, string> reportProgress);
|
Task SyncEquipments_Down(Action<double, string> reportProgress);
|
||||||
|
|
||||||
@@ -19,5 +19,7 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces
|
|||||||
|
|
||||||
Task SyncCheckListHeader_Down(Action<double, string> reportProgress);
|
Task SyncCheckListHeader_Down(Action<double, string> reportProgress);
|
||||||
Task<ApiResponseDTO<string>> SyncCheckListHeader_Up(int Id, Action<double, string> reportProgress);
|
Task<ApiResponseDTO<string>> SyncCheckListHeader_Up(int Id, Action<double, string> reportProgress);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces
|
|||||||
public interface IUserService
|
public interface IUserService
|
||||||
{
|
{
|
||||||
UserDTO? GetCurrentUser();
|
UserDTO? GetCurrentUser();
|
||||||
Task<ApiResponseDTO<UserDTO>> GetUserAsync();
|
Task<ApiResponseDTO<UserDTO>> GetUserAsync(int id);
|
||||||
|
Task<ApiResponseDTO<List<UserDTO>>> GetAllUserAsync();
|
||||||
Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password);
|
Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password);
|
||||||
|
Task<ApiResponseDTO<string>> SyncUsers_Up(Action<double, string> reportProgress);
|
||||||
void SetCurrentUser(UserDTO user);
|
void SetCurrentUser(UserDTO user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,16 +53,44 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
Console.WriteLine($"Hiba történt: {ex.Message}");
|
Console.WriteLine($"Hiba történt: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public async Task SyncCheckPoints_Up(Action<double, string> reportProgress)
|
public async Task<ApiResponseDTO<string>> SyncCheckPoints_Up(Action<double, string> reportProgress)
|
||||||
{
|
{
|
||||||
|
var retVal = new ApiResponseDTO<string>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
await PrepareAuthenticatedRequestAsync();
|
||||||
|
|
||||||
|
var checkPointList = await _dbContext.CheckPoints.ToListAsync();
|
||||||
|
|
||||||
|
var checkPointListDTO = _mapper.Map<List<CheckPointDTO>>(checkPointList);
|
||||||
|
var endpoint = $"{_httpClient.BaseAddress}api/Sync/UpdateAllCheckPoint";
|
||||||
|
|
||||||
|
var json = JsonConvert.SerializeObject(checkPointListDTO);
|
||||||
|
var jsonBytes = Encoding.UTF8.GetBytes(json);
|
||||||
|
var jsonStream = new MemoryStream(jsonBytes);
|
||||||
|
|
||||||
|
var progressContent = new ProgressableStreamContent(jsonStream, 8192, (uploaded, total) =>
|
||||||
|
{
|
||||||
|
double percentage = (double)uploaded / total * 100;
|
||||||
|
reportProgress(percentage, "Beküldés...");
|
||||||
|
});
|
||||||
|
|
||||||
|
progressContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
|
||||||
|
|
||||||
|
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsync(endpoint, progressContent))
|
||||||
|
{
|
||||||
|
httpResponseMessage.EnsureSuccessStatusCode();
|
||||||
|
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||||
|
retVal = JsonConvert.DeserializeObject<ApiResponseDTO<string>>(jsonString);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
// Hiba visszaadása
|
retVal.IsSuccess = false;
|
||||||
|
retVal.Errors.Add(ex.Message);
|
||||||
}
|
}
|
||||||
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SyncLocations_Down(Action<double, string> reportProgress)
|
public async Task SyncLocations_Down(Action<double, string> reportProgress)
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ using Newtonsoft.Json;
|
|||||||
using WorkFlowCheck.MAUI.DataLayer;
|
using WorkFlowCheck.MAUI.DataLayer;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using WorkFlowCheck.MAUI.Services.Interfaces;
|
using WorkFlowCheck.MAUI.Services.Interfaces;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using WorkFlowCheck.MAUI.Handlers;
|
||||||
|
|
||||||
namespace WorkFlowCheck.MAUI.Services
|
namespace WorkFlowCheck.MAUI.Services
|
||||||
{
|
{
|
||||||
@@ -22,15 +24,14 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
public UserService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper) : base(httpClient, configuration, dbContext, mapper)
|
public UserService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper) : base(httpClient, configuration, dbContext, mapper)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
public async Task<ApiResponseDTO<UserDTO>> GetUserAsync()
|
|
||||||
|
public async Task<ApiResponseDTO<UserDTO>> GetUserAsync(int id)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await PrepareAuthenticatedRequestAsync();
|
await PrepareAuthenticatedRequestAsync();
|
||||||
// Az API végpont meghatározása
|
|
||||||
string endpoint = $"{_httpClient.BaseAddress}api/User/1";
|
|
||||||
|
|
||||||
// HTTP GET kérés küldése
|
string endpoint = $"{_httpClient.BaseAddress}api/GetUser/{id}";
|
||||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserDTO>>(endpoint);
|
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserDTO>>(endpoint);
|
||||||
|
|
||||||
return response ?? new ApiResponseDTO<UserDTO>
|
return response ?? new ApiResponseDTO<UserDTO>
|
||||||
@@ -47,6 +48,29 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public async Task<ApiResponseDTO<List<UserDTO>>> GetAllUserAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await PrepareAuthenticatedRequestAsync();
|
||||||
|
|
||||||
|
string endpoint = $"{_httpClient.BaseAddress}api/GetAllUser";
|
||||||
|
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<UserDTO>>>(endpoint);
|
||||||
|
|
||||||
|
return response ?? new ApiResponseDTO<List<UserDTO>>
|
||||||
|
{
|
||||||
|
IsSuccess = false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
return new ApiResponseDTO<List<UserDTO>>
|
||||||
|
{
|
||||||
|
IsSuccess = false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
public async Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password)
|
public async Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -85,6 +109,45 @@ namespace WorkFlowCheck.MAUI.Services
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public async Task<ApiResponseDTO<string>> SyncUsers_Up(Action<double, string> reportProgress)
|
||||||
|
{
|
||||||
|
var retVal = new ApiResponseDTO<string>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await PrepareAuthenticatedRequestAsync();
|
||||||
|
|
||||||
|
var userList = await _dbContext.Users.ToListAsync();
|
||||||
|
|
||||||
|
var userListDTO = _mapper.Map<List<UserDTO>>(userList);
|
||||||
|
var endpoint = $"{_httpClient.BaseAddress}api/Sync/UpdateAllUser";
|
||||||
|
|
||||||
|
var json = JsonConvert.SerializeObject(userListDTO);
|
||||||
|
var jsonBytes = Encoding.UTF8.GetBytes(json);
|
||||||
|
var jsonStream = new MemoryStream(jsonBytes);
|
||||||
|
|
||||||
|
var progressContent = new ProgressableStreamContent(jsonStream, 8192, (uploaded, total) =>
|
||||||
|
{
|
||||||
|
double percentage = (double)uploaded / total * 100;
|
||||||
|
reportProgress(percentage, "Beküldés...");
|
||||||
|
});
|
||||||
|
|
||||||
|
progressContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
|
||||||
|
|
||||||
|
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsync(endpoint, progressContent))
|
||||||
|
{
|
||||||
|
httpResponseMessage.EnsureSuccessStatusCode();
|
||||||
|
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
|
||||||
|
retVal = JsonConvert.DeserializeObject<ApiResponseDTO<string>>(jsonString);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
retVal.IsSuccess = false;
|
||||||
|
retVal.Errors.Add(ex.Message);
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
public void SetCurrentUser(UserDTO user)
|
public void SetCurrentUser(UserDTO user)
|
||||||
{
|
{
|
||||||
CurrentUser = user;
|
CurrentUser = user;
|
||||||
|
|||||||
@@ -88,6 +88,12 @@
|
|||||||
<ProjectReference Include="..\WorkFlowCheck.Common\WorkFlowCheck.Common.csproj" />
|
<ProjectReference Include="..\WorkFlowCheck.Common\WorkFlowCheck.Common.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="Pages\Security\UsersPage.xaml.cs">
|
||||||
|
<DependentUpon>UsersPage.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<MauiXaml Update="ContentViews\HeaderView.xaml">
|
<MauiXaml Update="ContentViews\HeaderView.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
@@ -122,6 +128,9 @@
|
|||||||
<MauiXaml Update="Pages\NFC\NFCWaiter.xaml">
|
<MauiXaml Update="Pages\NFC\NFCWaiter.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</MauiXaml>
|
</MauiXaml>
|
||||||
|
<MauiXaml Update="Pages\Security\UsersPage.xaml">
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</MauiXaml>
|
||||||
<MauiXaml Update="Pages\Security\LoginPage.xaml">
|
<MauiXaml Update="Pages\Security\LoginPage.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</MauiXaml>
|
</MauiXaml>
|
||||||
|
|||||||
Reference in New Issue
Block a user