From 146402a96a5baa428f494c306db41879d1d0173a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Szab=C3=B3?= Date: Fri, 28 Mar 2025 20:51:00 +0100 Subject: [PATCH] Snackbar meg ilyesmik --- .../Pages/CheckList/CheckListWorkPage.xaml.cs | 18 ++++++++++-- .../Pages/Security/LoginPage.xaml.cs | 29 ++++++++++++++++--- .../Services/CheckListService.cs | 5 +++- .../Services/Interfaces/ISyncService.cs | 3 +- .../Services/SyncService.cs | 28 ++++++++++++++++++ 5 files changed, 75 insertions(+), 8 deletions(-) diff --git a/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListWorkPage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListWorkPage.xaml.cs index c2a4d5c..b3973c2 100644 --- a/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListWorkPage.xaml.cs +++ b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListWorkPage.xaml.cs @@ -11,10 +11,14 @@ namespace WorkFlowCheck.MAUI.Pages.CheckList; public partial class CheckListWorkPage : ContentPage { private readonly ICheckListService _checkListService; + private readonly ISyncService _syncService; + private string _checkPointCode; private int _checkListHeaderId; private UserDTO _userDTO; private bool _isLoading; + + public bool IsLoading { get => _isLoading; @@ -35,6 +39,7 @@ public partial class CheckListWorkPage : ContentPage _checkPointCode = checkPointCode; _checkListHeaderId = checkListHeaderId; _checkListService = MauiProgram.ServiceProvider.GetRequiredService(); + _syncService = MauiProgram.ServiceProvider.GetRequiredService(); _userDTO = MauiProgram.ServiceProvider.GetRequiredService().GetCurrentUser(); SaveCommand = new Command(OnSave); @@ -43,7 +48,17 @@ public partial class CheckListWorkPage : ContentPage private async void OnSend() { - + IsLoading = true; + try + { + OnSave(); + await _syncService.SyncCheckListHeaderUp(_checkListHeaderId); + } + catch (Exception ex) + { + await Application.Current.MainPage.DisplayAlert("Hiba", ex.Message, "OK"); + } + IsLoading = false; } private async void OnSave() { @@ -74,7 +89,6 @@ public partial class CheckListWorkPage : ContentPage } } - protected override async void OnAppearing() { base.OnAppearing(); diff --git a/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs index 09a8708..44d02bc 100644 --- a/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs +++ b/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs @@ -1,10 +1,13 @@ +using CommunityToolkit.Maui.Alerts; +using CommunityToolkit.Maui.Core; +using System.Drawing; using WorkFlowCheck.MAUI.Services.Interfaces; namespace WorkFlowCheck.MAUI.Pages.Security; public partial class LoginPage : ContentPage { - private IUserService _userService; + private IUserService _userService; private ISyncService _syncService; public LoginPage() { @@ -26,17 +29,35 @@ public partial class LoginPage : ContentPage if (response != null && response.IsSuccess) { _userService.SetCurrentUser(response.Data); - await _syncService.SyncDatas(); + await _syncService.SyncDatas(); var wFCUser = Newtonsoft.Json.JsonConvert.SerializeObject(response.Data); await SecureStorage.Default.SetAsync("WFCUser", "wFCUser"); - await SecureStorage.Default.SetAsync("AuthToken", response.Data.JwtToken); + await SecureStorage.Default.SetAsync("AuthToken", response.Data.JwtToken); await Shell.Current.GoToAsync("//MainPage"); } else { - await DisplayAlert("Error", "Invalid login credentials.", "OK"); + + var visualOptions = new SnackbarOptions + { + ActionButtonTextColor = Colors.Yellow, + CornerRadius = new CornerRadius(10), + Font = Microsoft.Maui.Font.SystemFontOfSize(16), + BackgroundColor = Microsoft.Maui.Graphics.Color.Parse("Red"), + TextColor=Colors.Yellow + + }; + var snackbar = Snackbar.Make( + "Invalid login credentials.", + duration: TimeSpan.FromSeconds(10), + action: () => Console.WriteLine("Snackbar dismissed"), + actionButtonText: "OK", + visualOptions: visualOptions + ); + + await snackbar.Show(); } } catch (Exception) diff --git a/src/WorkFlowCheck.MAUI/Services/CheckListService.cs b/src/WorkFlowCheck.MAUI/Services/CheckListService.cs index 7e2f14f..3f2e59b 100644 --- a/src/WorkFlowCheck.MAUI/Services/CheckListService.cs +++ b/src/WorkFlowCheck.MAUI/Services/CheckListService.cs @@ -163,7 +163,10 @@ namespace WorkFlowCheck.MAUI.Services if (checkListRow != null) { checkListRow.Answer = checkListRowDTO.Answer; - checkListRow.Photo = checkListRowDTO.Photo; + if (checkListRowDTO.Photo != null && checkListRowDTO.Photo.Length > 0) + { + checkListRow.Photo = checkListRowDTO.Photo; + } await _dbContext.SaveChangesAsync(); } } diff --git a/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs b/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs index 1841a73..0007df7 100644 --- a/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs +++ b/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using WorkFlowCheck.Common.DTO; namespace WorkFlowCheck.MAUI.Services.Interfaces { @@ -14,6 +15,6 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces Task SyncLocations(); Task SyncEquipments(); - + Task SyncCheckListHeaderUp(int Id); } } diff --git a/src/WorkFlowCheck.MAUI/Services/SyncService.cs b/src/WorkFlowCheck.MAUI/Services/SyncService.cs index e7dd728..a988969 100644 --- a/src/WorkFlowCheck.MAUI/Services/SyncService.cs +++ b/src/WorkFlowCheck.MAUI/Services/SyncService.cs @@ -254,5 +254,33 @@ namespace WorkFlowCheck.MAUI.Services } } + + public async Task SyncCheckListHeaderUp(int Id) + { + try + { + await PrepareAuthenticatedRequestAsync(); + + var checkListHeader = await _dbContext.CheckListHeaders + .Include(i => i.CheckListRows) + .AsNoTracking() + .ToListAsync(); + var checkListHeaderDTO = _mapper.Map(checkListHeader); + + + var endpoint = $"{_httpClient.BaseAddress}api/Sync/UpdateCheckListHeader"; + using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, checkListHeaderDTO)) + { + httpResponseMessage.EnsureSuccessStatusCode(); + var jsonString = await httpResponseMessage.Content.ReadAsStringAsync(); + var response = JsonConvert.DeserializeObject>(jsonString); + } + } + catch (Exception ex) + { + // Hiba visszaadása + } + + } } }