The cloud manager acts as an intermediary for syncing between the local biskilog server manager and the biskilog accounting web application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.7 KiB

2 years ago
using Cloud_Manager;
using Cloud_Manager.Models.Enums;
using Cloud_Manager.Models.Interfaces;
using Cloud_Manager.Models.POSModels;
using Microsoft.EntityFrameworkCore;
using Microsoft.Net.Http.Headers;
using MySqlConnector;
using System.Text.Json;
namespace Cloud_Manager.Services
{
public class UserService : IUser
{
private readonly BiskAcdbContext m_context;
2 years ago
private readonly IKeyService m_tokenService;
2 years ago
private readonly HttpContext m_httpContext;
2 years ago
public UserService(BiskAcdbContext a_context, IKeyService a_tokenService, IHttpContextAccessor a_httpContextAccessor)
2 years ago
{
m_context = a_context;
m_tokenService = a_tokenService;
m_httpContext = a_httpContextAccessor?.HttpContext;
}
public IEnumerable<Tbluser> FetchUsers()
{
2 years ago
throw new NotImplementedException();
2 years ago
}
public Task<IEnumerable<Tbluser>> GetUsers()
{
throw new NotImplementedException();
}
public async Task SyncUserAsync(List<Tbluser> a_users)
{
2 years ago
string apiKey = m_httpContext.Request.Headers["BISK-API-KEY"]!;
if (AuthEnums.Valid == m_tokenService.ValidateKey(apiKey))
2 years ago
{
string jsonString = JsonSerializer.Serialize(a_users);
using (var command = m_context.Database.GetDbConnection().CreateCommand())
{
m_context.Database.OpenConnection();
command.CommandText = "CALL UsersSync(@p0)";
command.Parameters.Add(new MySqlParameter("@p0", jsonString));
command.ExecuteNonQuery();
}
}
}
}
}