Userhez is lehet már NFC kódot rendelni
This commit is contained in:
@@ -12,7 +12,7 @@ namespace WorkFlowCheck.Common.DTO
|
||||
public string? UserName { get; set; }
|
||||
public string? FirstName { get; set; }
|
||||
public string? LastName { get; set; }
|
||||
public string? Fullname => $"{LastName} {FirstName}";
|
||||
public string? FullName => $"{LastName} {FirstName}";
|
||||
public string? Email { get; set; }
|
||||
public bool NFCActive { get; set; }
|
||||
public string NFCCode { get; set; } = null!;
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using Android.Util;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Json;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
|
||||
namespace WorkFlowCheck.MAUI.Helper
|
||||
{
|
||||
public static class SystemHelper
|
||||
{
|
||||
public static string DatabaseName = "";
|
||||
#if DEBUG
|
||||
public static string ApiBaseUrl = $"https://dev.wfcapi.nuvolar.hu/";
|
||||
public static string ApiKey = $"RUJeLSpSMzVASUdaRCEzUyYxRSE0VyFISFRSJC0zRzhLM1hCSDU=";
|
||||
|
||||
#endif
|
||||
#if !DEBUG
|
||||
public static string ApiBaseUrl = $"https://wfcapi.nuvolar.hu/";
|
||||
public static string ApiKey = $"RUJeLSpSMzVASUdaRCEzUyYxRSE0VyFISFRSJC0zRzhLM1hCSDU=";
|
||||
#endif
|
||||
public async static Task GetAPIInfoAsync()
|
||||
{
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
|
||||
httpClient.BaseAddress = new Uri(ApiBaseUrl);
|
||||
httpClient.DefaultRequestHeaders.Add("X-Api-Key", ApiKey);
|
||||
|
||||
string endpoint = $"{ApiBaseUrl}api/System/GetDatabaseAndVersionInfo";
|
||||
var retVal = new RoleDTO();
|
||||
try
|
||||
{
|
||||
var response = await httpClient.GetFromJsonAsync<ApiResponseDTO<string>>(endpoint);
|
||||
if (response != null)
|
||||
{
|
||||
if (response.IsSuccess)
|
||||
{
|
||||
DatabaseName = response.Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Log.Error(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using DevExpress.Entity.Model.Metadata;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
using WorkFlowCheck.MAUI.Helper;
|
||||
using WorkFlowCheck.MAUI.Pages.Media;
|
||||
using WorkFlowCheck.MAUI.Services.Interfaces;
|
||||
namespace WorkFlowCheck.MAUI
|
||||
@@ -19,7 +20,7 @@ namespace WorkFlowCheck.MAUI
|
||||
private void SetInfo()
|
||||
{
|
||||
_currentUser = _userService.GetCurrentUser();
|
||||
DeviceId.Text = _userService.DeviceId;
|
||||
DeviceId.Text = $"{_userService.DeviceId}";
|
||||
UserInfo.Text = $"{_currentUser?.FirstName} {_currentUser?.LastName}";
|
||||
}
|
||||
override protected async void OnAppearing()
|
||||
@@ -59,7 +60,7 @@ namespace WorkFlowCheck.MAUI
|
||||
}
|
||||
private void OnButtonLogout(object sender, EventArgs e)
|
||||
{
|
||||
_userService.SetCurrentUser(null);
|
||||
_userService.SetCurrentUser(null);
|
||||
SecureStorage.Default.Remove("WFCUser");
|
||||
SecureStorage.Default.Remove("AuthToken");
|
||||
Shell.Current.GoToAsync("//LoginPage");
|
||||
|
||||
@@ -34,7 +34,10 @@ namespace WorkFlowCheck.MAUI.Mapper
|
||||
CreateMap<CheckListRow, CheckListRowDTO>()
|
||||
.ForMember(dest => dest.CheckListTemplateRowDTO, opt => opt.MapFrom(src => src.CheckListTemplateRow));
|
||||
CreateMap<CheckListRowDTO, CheckListRow>()
|
||||
.ForMember(dest => dest.CheckListTemplateRow, opt => opt.MapFrom(src => src.CheckListTemplateRowDTO));
|
||||
.ForMember(dest => dest.CheckListTemplateRow, opt => opt.MapFrom(src => src.CheckListTemplateRowDTO));
|
||||
|
||||
CreateMap<MobileUser, MobileUserDTO>();
|
||||
CreateMap<MobileUserDTO, MobileUser>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WorkFlowCheck.MAUI.Services;
|
||||
using Microsoft.Extensions.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -12,6 +11,7 @@ using Microsoft.Maui.Controls.Hosting;
|
||||
using Microsoft.Maui.Hosting;
|
||||
using CommunityToolkit.Maui.Core;
|
||||
using WorkFlowCheck.MAUI.Handlers;
|
||||
using WorkFlowCheck.MAUI.Helper;
|
||||
|
||||
namespace WorkFlowCheck.MAUI
|
||||
{
|
||||
@@ -21,27 +21,14 @@ namespace WorkFlowCheck.MAUI
|
||||
{
|
||||
var builder = MauiApp.CreateBuilder();
|
||||
builder.UseDevExpress(useLocalization: false)
|
||||
.UseDevExpressControls()
|
||||
.UseDevExpressCollectionView();
|
||||
.UseDevExpressControls()
|
||||
.UseDevExpressCollectionView();
|
||||
|
||||
builder.Services.AddAutoMapper(typeof(MapperProfile));
|
||||
// appsettings.json beállítása
|
||||
string jsonFilePath = Path.Combine(FileSystem.AppDataDirectory, "appsettings.json");
|
||||
// Másold a fájlt a Raw erőforrásokból az AppDataDirectory-ba, ha még nincs ott
|
||||
if (!File.Exists(jsonFilePath))
|
||||
{
|
||||
using var stream = FileSystem.OpenAppPackageFileAsync("appsettings.json").Result;
|
||||
using var reader = new StreamReader(stream);
|
||||
File.WriteAllText(jsonFilePath, reader.ReadToEnd());
|
||||
}
|
||||
|
||||
var configuration = new ConfigurationBuilder().SetBasePath(FileSystem.AppDataDirectory) // A konfigurációs fájl betöltése az alkalmazás adat könyvtárából
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build();
|
||||
|
||||
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddDbContext<AppDbContext>();
|
||||
|
||||
builder.Services.AddSingleton<IConfiguration>(configuration);
|
||||
|
||||
builder.Services.AddSingleton<IUserService, UserService>();
|
||||
builder.Services.AddSingleton<ISyncService, SyncService>();
|
||||
builder.Services.AddSingleton<IBaseStockService, BaseStockService>();
|
||||
@@ -64,9 +51,18 @@ namespace WorkFlowCheck.MAUI
|
||||
#if DEBUG
|
||||
builder.Logging.AddDebug();
|
||||
#endif
|
||||
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await SystemHelper.GetAPIInfoAsync();
|
||||
}).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
|
||||
ServiceProvider = app.Services;
|
||||
return app;
|
||||
}
|
||||
|
||||
@@ -66,6 +66,10 @@
|
||||
<Button Text="Blokkolás"
|
||||
Margin="5,0,0,0"
|
||||
BackgroundColor="Red"
|
||||
HeightRequest="50"
|
||||
MaximumHeightRequest="50"
|
||||
WidthRequest="120"
|
||||
MaximumWidthRequest="120"
|
||||
IsVisible="{Binding CheckStatus, Converter={StaticResource BlockedConverter}}"
|
||||
Command="{Binding BindingContext.BlockCommand, Source={x:Reference CheckList}}"
|
||||
CommandParameter="{Binding .}">
|
||||
@@ -73,6 +77,10 @@
|
||||
<Button Text="Feloldás"
|
||||
Margin="5,0,0,0"
|
||||
BackgroundColor="Green"
|
||||
HeightRequest="50"
|
||||
MaximumHeightRequest="50"
|
||||
WidthRequest="120"
|
||||
MaximumWidthRequest="120"
|
||||
IsVisible="{Binding CheckStatus, Converter={StaticResource UnBlockedConverter}}"
|
||||
Command="{Binding BindingContext.UnblockCommand, Source={x:Reference CheckList}}"
|
||||
CommandParameter="{Binding .}">
|
||||
@@ -80,6 +88,10 @@
|
||||
<Button Text="Folytatás"
|
||||
Margin="5,0,0,0"
|
||||
BackgroundColor="Blue"
|
||||
HeightRequest="50"
|
||||
MaximumHeightRequest="50"
|
||||
WidthRequest="120"
|
||||
MaximumWidthRequest="120"
|
||||
IsVisible="{Binding CheckStatus, Converter={StaticResource ContinueConverter}}"
|
||||
Command="{Binding BindingContext.ContinueCommand, Source={x:Reference CheckList}}"
|
||||
CommandParameter="{Binding .}">
|
||||
@@ -116,6 +128,10 @@
|
||||
<Button Text="Új ellenőrzés"
|
||||
BackgroundColor="Green"
|
||||
Margin="5,0,0,0"
|
||||
HeightRequest="50"
|
||||
MaximumHeightRequest="50"
|
||||
WidthRequest="120"
|
||||
MaximumWidthRequest="120"
|
||||
Command="{Binding BindingContext.NewCommand, Source={x:Reference CheckListTemplate}}"
|
||||
CommandParameter="{Binding .}" />
|
||||
</HorizontalStackLayout>
|
||||
|
||||
@@ -50,7 +50,7 @@ public partial class CheckListPage : ContentPage
|
||||
{
|
||||
_currentUser = _userService.GetCurrentUser();
|
||||
DeviceId.Text = _userService.DeviceId;
|
||||
UserInfo.Text = $"{_currentUser?.FirstName} {_currentUser?.LastName}";
|
||||
UserInfo.Text = $"{_currentUser?.LastName} {_currentUser?.FirstName}";
|
||||
}
|
||||
protected override bool OnBackButtonPressed()
|
||||
{
|
||||
|
||||
@@ -17,18 +17,21 @@
|
||||
<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 .}" />
|
||||
<Grid ColumnDefinitions="*,Auto">
|
||||
<StackLayout Grid.Column="0" Spacing="2">
|
||||
<Label Text="{Binding FullName}" FontSize="16" FontAttributes="Bold" />
|
||||
<Label Text="{Binding NFCCode}" FontSize="14" />
|
||||
</StackLayout>
|
||||
<HorizontalStackLayout Grid.Column="1" HorizontalOptions="End" Spacing="5">
|
||||
<Button Text="Párosítás" Margin="5,0,0,0"
|
||||
HeightRequest="50"
|
||||
MaximumHeightRequest="50"
|
||||
WidthRequest="120"
|
||||
MaximumWidthRequest="120"
|
||||
Command="{Binding BindingContext.PairCommand, Source={x:Reference UsersList}}"
|
||||
CommandParameter="{Binding .}" />
|
||||
</HorizontalStackLayout>
|
||||
</StackLayout>
|
||||
</Grid>
|
||||
</Frame>
|
||||
</DataTemplate>
|
||||
</CollectionView.ItemTemplate>
|
||||
|
||||
@@ -9,12 +9,13 @@ public partial class UsersPage : ContentPage
|
||||
{
|
||||
|
||||
private readonly IUserService _userService;
|
||||
|
||||
private readonly ISyncService _syncService;
|
||||
|
||||
public UsersPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
_userService = MauiProgram.ServiceProvider.GetRequiredService<IUserService>();
|
||||
_syncService = MauiProgram.ServiceProvider.GetRequiredService<ISyncService>();
|
||||
}
|
||||
|
||||
public ICommand RefreshCommand { get; set; }
|
||||
@@ -25,7 +26,7 @@ public partial class UsersPage : ContentPage
|
||||
{
|
||||
base.OnAppearing();
|
||||
RefreshCommand = new Command(async () => await LoadUsers());
|
||||
PairCommand = new Command<UserDTO>(OnPairItem);
|
||||
PairCommand = new Command<MobileUserDTO>(OnPairItem);
|
||||
|
||||
BindingContext = this;
|
||||
await LoadUsers();
|
||||
@@ -35,12 +36,12 @@ public partial class UsersPage : ContentPage
|
||||
{
|
||||
IsRefreshing = true;
|
||||
//await _syncService.SyncDatas();
|
||||
//UsersList.ItemsSource = await _userService.GetAllUserAsync().Result.Data;
|
||||
UsersList.ItemsSource = await _userService.GetAllMobileUserAsync();
|
||||
IsRefreshing = false;
|
||||
OnPropertyChanged(nameof(IsRefreshing));
|
||||
}
|
||||
|
||||
private async void OnPairItem(UserDTO UserDTO)
|
||||
private async void OnPairItem(MobileUserDTO mobileUserDTO)
|
||||
{
|
||||
var UserCode = await NFCWaiter.ShowModalAsync();
|
||||
if (!string.IsNullOrEmpty(UserCode))
|
||||
@@ -49,10 +50,11 @@ public partial class UsersPage : ContentPage
|
||||
{
|
||||
await Navigation.PopModalAsync();
|
||||
}
|
||||
if (UserDTO != null)
|
||||
if (mobileUserDTO != null)
|
||||
{
|
||||
//UserDTO.Code = UserCode;
|
||||
//await _baseStockService.UpdateUser(UserDTO);
|
||||
mobileUserDTO.NFCCode = UserCode;
|
||||
|
||||
await _userService.UpdateCheckPoint(mobileUserDTO);
|
||||
await LoadUsers();
|
||||
}
|
||||
}
|
||||
@@ -74,7 +76,7 @@ public partial class UsersPage : ContentPage
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
await _userService.SyncUsers_Up((percentage, infostring) =>
|
||||
await _syncService.SyncUsers_Up((percentage, infostring) =>
|
||||
{
|
||||
MainThread.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"ApiBaseUrl": "https://wfcapi.nuvolar.hu/",
|
||||
"ApiBaseUrl": "https://dev.wfcapi.nuvolar.hu/",
|
||||
"ApiKey": "RUJeLSpSMzVASUdaRCEzUyYxRSE0VyFISFRSJC0zRzhLM1hCSDU="
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using WorkFlowCheck.MAUI.DataLayer;
|
||||
using WorkFlowCheck.MAUI.Services.Interfaces;
|
||||
using Android.Provider;
|
||||
using Android.DeviceLock;
|
||||
using WorkFlowCheck.MAUI.Helper;
|
||||
|
||||
namespace WorkFlowCheck.MAUI.Services
|
||||
{
|
||||
@@ -20,24 +21,23 @@ namespace WorkFlowCheck.MAUI.Services
|
||||
{
|
||||
public readonly HttpClient _httpClient;
|
||||
public readonly AppDbContext _dbContext;
|
||||
public readonly IConfiguration _configuration;
|
||||
|
||||
public readonly IMapper _mapper;
|
||||
private string _deviceId;
|
||||
public string DeviceId => _deviceId.ToUpper(); // Getter a DeviceId-hez
|
||||
public string DeviceId => $"{_deviceId.ToUpper()}:{SystemHelper.DatabaseName}"; // Getter a DeviceId-hez
|
||||
|
||||
public BaseService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper)
|
||||
public BaseService(HttpClient httpClient, AppDbContext dbContext, IMapper mapper)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_dbContext = dbContext;
|
||||
_configuration = configuration;
|
||||
_mapper = mapper;
|
||||
|
||||
var apiBaseUrl = configuration["ApiBaseUrl"]; // API-cím elérése a konfigurációból
|
||||
var apiBaseUrl = SystemHelper.ApiBaseUrl;
|
||||
_httpClient.BaseAddress = new Uri(apiBaseUrl);
|
||||
|
||||
var apiKey = configuration["ApiKey"];
|
||||
var apiKey = SystemHelper.ApiKey;
|
||||
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiKey);
|
||||
_deviceId = GetDeviceId();
|
||||
_deviceId = GetDeviceId();
|
||||
}
|
||||
protected async Task PrepareAuthenticatedRequestAsync()
|
||||
{
|
||||
|
||||
@@ -16,14 +16,13 @@ namespace WorkFlowCheck.MAUI.Services
|
||||
{
|
||||
public class BaseStockService : BaseService, IBaseStockService
|
||||
{
|
||||
public BaseStockService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper) : base(httpClient, configuration, dbContext, mapper)
|
||||
public BaseStockService(HttpClient httpClient, AppDbContext dbContext, IMapper mapper) : base(httpClient, dbContext, mapper)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<CheckPointDTO>> GetAllCheckPoints()
|
||||
{
|
||||
return _mapper.Map<List<CheckPointDTO>>(await _dbContext.CheckPoints.ToListAsync());
|
||||
|
||||
}
|
||||
public async Task<CheckPointDTO> GetCheckPoint(int id)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace WorkFlowCheck.MAUI.Services
|
||||
AppDbContext dbContext,
|
||||
IMapper mapper,
|
||||
IUserService userService,
|
||||
ISyncService syncService) : base(httpClient, configuration, dbContext, mapper)
|
||||
ISyncService syncService) : base(httpClient, dbContext, mapper)
|
||||
{
|
||||
_userService = userService;
|
||||
_syncService = syncService;
|
||||
|
||||
@@ -22,5 +22,8 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces
|
||||
Task<ApiResponseDTO<string>> SyncCheckListHeader_Up(int Id, Action<double, string> reportProgress);
|
||||
|
||||
Task<List<DeviceMessageDTO>> DeviceMessageReadUnreaded(string deviceIdBase64);
|
||||
|
||||
Task<ApiResponseDTO<string>> SyncUsers_Up(Action<double, string> reportProgress);
|
||||
Task SyncUsers_Down(Action<double, string> reportProgress);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,15 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces
|
||||
UserDTO? GetCurrentUser();
|
||||
string DeviceId { get; }
|
||||
Task<ApiResponseDTO<UserDTO>> GetUserAsync(int id);
|
||||
Task<ApiResponseDTO<List<UserDTO>>> GetAllUserAsync();
|
||||
|
||||
|
||||
Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password);
|
||||
Task<ApiResponseDTO<UserDTO>> AuthenticateNFC(string NFCCode);
|
||||
Task<ApiResponseDTO<string>> SyncUsers_Up(Action<double, string> reportProgress);
|
||||
|
||||
void SetCurrentUser(UserDTO user);
|
||||
|
||||
|
||||
Task<MobileUserDTO> UpdateCheckPoint(MobileUserDTO mobileUserDTO);
|
||||
Task<List<MobileUserDTO>> GetAllMobileUserAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace WorkFlowCheck.MAUI.Services
|
||||
{
|
||||
private readonly IUserService _userService;
|
||||
|
||||
public SyncService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper, IUserService userService) : base(httpClient, configuration, dbContext, mapper)
|
||||
public SyncService(HttpClient httpClient, AppDbContext dbContext, IMapper mapper, IUserService userService) : base(httpClient, dbContext, mapper)
|
||||
{
|
||||
_userService = userService;
|
||||
}
|
||||
@@ -34,6 +34,7 @@ namespace WorkFlowCheck.MAUI.Services
|
||||
await SyncEquipments_Down(reportProgress);
|
||||
await SyncCheckListTemplates_Down(reportProgress);
|
||||
await SyncCheckListHeader_Down(reportProgress);
|
||||
await SyncUsers_Down(reportProgress);
|
||||
}
|
||||
public async Task DownloadAPK(Action<double, string> reportProgress)
|
||||
{
|
||||
@@ -404,5 +405,72 @@ namespace WorkFlowCheck.MAUI.Services
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public async Task<ApiResponseDTO<string>> SyncUsers_Up(Action<double, string> reportProgress)
|
||||
{
|
||||
var retVal = new ApiResponseDTO<string>();
|
||||
try
|
||||
{
|
||||
await PrepareAuthenticatedRequestAsync();
|
||||
|
||||
var userList = await _dbContext.MobileUsers.ToListAsync();
|
||||
|
||||
var mobileUserListDTO = _mapper.Map<List<MobileUserDTO>>(userList);
|
||||
var endpoint = $"{_httpClient.BaseAddress}api/Sync/UpdateAllMobileUser";
|
||||
|
||||
var json = JsonConvert.SerializeObject(mobileUserListDTO, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
|
||||
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 async Task SyncUsers_Down(Action<double, string> reportProgress)
|
||||
{
|
||||
try
|
||||
{
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllMobileUsers";
|
||||
var responseList = DownloadDataAsync<MobileUserDTO>(endpoint, reportProgress).Result;
|
||||
|
||||
if (responseList != null)
|
||||
{
|
||||
if (responseList.IsSuccess)
|
||||
{
|
||||
var entityList = await _dbContext.MobileUsers.ToListAsync();
|
||||
var missingItems = responseList.Data.Where(f => !entityList.Any(s => s.Id == f.Id)).ToList();
|
||||
|
||||
var mappedMissingItems = _mapper.Map<List<MobileUser>>(missingItems);
|
||||
|
||||
_dbContext.MobileUsers.AddRange(mappedMissingItems);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Hiba visszaadása
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ using AutoMapper;
|
||||
using WorkFlowCheck.MAUI.Services.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WorkFlowCheck.MAUI.Handlers;
|
||||
using WorkFlowCheck.MAUI.DataLayer.Entities;
|
||||
|
||||
namespace WorkFlowCheck.MAUI.Services
|
||||
{
|
||||
@@ -22,7 +23,7 @@ namespace WorkFlowCheck.MAUI.Services
|
||||
{
|
||||
public UserDTO? CurrentUser { get; private set; }
|
||||
|
||||
public UserService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper) : base(httpClient, configuration, dbContext, mapper)
|
||||
public UserService(HttpClient httpClient, AppDbContext dbContext, IMapper mapper) : base(httpClient, dbContext, mapper)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -49,29 +50,7 @@ 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)
|
||||
{
|
||||
try
|
||||
@@ -148,50 +127,42 @@ 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.MobileUsers.ToListAsync();
|
||||
|
||||
var userListDTO = _mapper.Map<List<UserDTO>>(userList);
|
||||
var endpoint = $"{_httpClient.BaseAddress}api/Sync/UpdateAllUser";
|
||||
|
||||
var json = JsonConvert.SerializeObject(userListDTO, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
|
||||
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)
|
||||
{
|
||||
CurrentUser = user;
|
||||
}
|
||||
public UserDTO? GetCurrentUser() => CurrentUser;
|
||||
|
||||
|
||||
public async Task<MobileUserDTO> UpdateCheckPoint(MobileUserDTO mobileUserDTO)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var existingEntity = await _dbContext.MobileUsers.FindAsync(mobileUserDTO.Id);
|
||||
|
||||
if (existingEntity == null)
|
||||
{
|
||||
throw new Exception("MobileUser not found.");
|
||||
}
|
||||
|
||||
|
||||
existingEntity.NFCCode = mobileUserDTO.NFCCode;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
mobileUserDTO = _mapper.Map<MobileUserDTO>(existingEntity);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
return mobileUserDTO;
|
||||
}
|
||||
public async Task<List<MobileUserDTO>> GetAllMobileUserAsync()
|
||||
{
|
||||
return _mapper.Map<List<MobileUserDTO>>(await _dbContext.MobileUsers.ToListAsync());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Helper\" />
|
||||
<Folder Include="Platforms\Android\Resources\mipmap-hdpi\" />
|
||||
<Folder Include="Platforms\Android\Resources\mipmap-xhdpi\" />
|
||||
<Folder Include="Platforms\Android\Resources\mipmap-xxhdpi\" />
|
||||
|
||||
Reference in New Issue
Block a user