FÉLKÉSZ
This commit is contained in:
@@ -13,6 +13,8 @@ using Newtonsoft.Json;
|
||||
using WorkFlowCheck.MAUI.DataLayer;
|
||||
using AutoMapper;
|
||||
using WorkFlowCheck.MAUI.Services.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WorkFlowCheck.MAUI.Handlers;
|
||||
|
||||
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 async Task<ApiResponseDTO<UserDTO>> GetUserAsync()
|
||||
|
||||
public async Task<ApiResponseDTO<UserDTO>> GetUserAsync(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
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);
|
||||
|
||||
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)
|
||||
{
|
||||
try
|
||||
@@ -58,7 +82,7 @@ namespace WorkFlowCheck.MAUI.Services
|
||||
{
|
||||
UserName = username,
|
||||
Password = password,
|
||||
|
||||
|
||||
};
|
||||
|
||||
// HTTP POST kérés küldése
|
||||
@@ -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)
|
||||
{
|
||||
CurrentUser = user;
|
||||
|
||||
Reference in New Issue
Block a user