using Biskilog_Cloud.Shared.CustomModels; using Biskilog_Cloud.Shared.Interfaces; using Biskilog_Cloud.Shared.Models; using Dapper; using Microsoft.EntityFrameworkCore; using System.Data; using System.Data.SqlClient; namespace ServerManager.ServiceRepo { public class ProductsService : IProduct { private readonly BiskPosContext m_context; private string m_connection; public ProductsService(BiskPosContext a_context, IConfiguration configuration) { m_context = a_context; m_connection = configuration.GetConnectionString("connection")!.ToString(); } public event EventHandler ProductsChanged; public event EventHandler UnitsChanged; public event EventHandler BrandsChanged; public event EventHandler CategoriesChanged; public async Task> FetchBrandsAsync(DateTime a_lastSync, string a_branch) { try { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "TblBrand", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); return new List(); } } public async Task> FetchCategoriesAsync(DateTime a_lastSync, string a_branch) { try { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tblcategory", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); return new List(); } } public async Task> FetchInventory(DateTime a_lastSync, string a_branch) { try { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "TblInventory", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); return new List(); } } public async Task> FetchInventoryEntries(DateTime a_lastSync, string a_branch) { try { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "TblInventoryentries", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); return new List(); } } public async Task> FetchPriceChanges(DateTime a_lastSync, string a_branch) { try { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "tblpricechanges", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); return new List(); } } public async Task> FetchProductAltUnit(DateTime a_lastSync, string a_branch) { try { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "productaltunit", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); return new List(); } } public async Task> FetchProducts(DateTime a_lastSync, string a_branch) { try { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { branchID = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchProductTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); return new List(); } } public async Task> FetchRestockAsync(DateTime a_lastSync, string a_branch) { try { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "Restocklevels", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); return new List(); } } public async Task> FetchStockAsync(DateTime a_lastSync, string a_branch) { try { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "Tbstock", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); return new List(); } } public async Task> FetchUnitOfMeasureAsync(DateTime a_lastSync, string a_branch) { try { using (IDbConnection dbConnection = new SqlConnection(m_connection)) { dbConnection.Open(); // Using Dapper to call a stored procedure with parameters var parameters = new { a_tableName = "unitofmeasure", a_branchId = a_branch, lastModified = a_lastSync }; List result = (await dbConnection.QueryAsync( "FetchTableRows", parameters, commandType: CommandType.StoredProcedure)).AsList(); return result; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); return new List(); } } public Task FetchBrands() { throw new NotImplementedException(); } public Task FetchLowStockProducts() { throw new NotImplementedException(); } public Task FetchCategories() { throw new NotImplementedException(); } public Task FetchProducts() { throw new NotImplementedException(); } public Task FetchUnits() { throw new NotImplementedException(); } public IEnumerable GetBrands(string a_brandKey = "") { throw new NotImplementedException(); } public IEnumerable GetCategories(string a_categoryKey = "") { throw new NotImplementedException(); } public IEnumerable GetLowstockItems() { throw new NotImplementedException(); } public ProductItem GetProductById(string a_id) { throw new NotImplementedException(); } public ProductItem GetProductByName(string name) { throw new NotImplementedException(); } public IEnumerable GetProducts(string a_productKey = "") { throw new NotImplementedException(); } public string GetUnitName(string a_unitCode) { throw new NotImplementedException(); } public IEnumerable GetUnitofmeasures() { throw new NotImplementedException(); } public void RefreshList() { throw new NotImplementedException(); } } }