Biskilog local server manager for the Biskilog POS desktop 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.

391 lines
13 KiB

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<IEnumerable<TblBrand>> 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<TblBrand> result = (await dbConnection.QueryAsync<TblBrand>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return new List<TblBrand>();
}
}
public async Task<IEnumerable<TblCategory>> 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<TblCategory> result = (await dbConnection.QueryAsync<TblCategory>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return new List<TblCategory>();
}
}
public async Task<IEnumerable<TblInventory>> 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<TblInventory> result = (await dbConnection.QueryAsync<TblInventory>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return new List<TblInventory>();
}
}
public async Task<IEnumerable<TblInventoryEntry>> 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<TblInventoryEntry> result = (await dbConnection.QueryAsync<TblInventoryEntry>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return new List<TblInventoryEntry>();
}
}
public async Task<IEnumerable<TblPriceChange>> 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<TblPriceChange> result = (await dbConnection.QueryAsync<TblPriceChange>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return new List<TblPriceChange>();
}
}
public async Task<IEnumerable<ProductAltUnit>> 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<ProductAltUnit> result = (await dbConnection.QueryAsync<ProductAltUnit>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return new List<ProductAltUnit>();
}
}
public async Task<IEnumerable<TblProduct>> 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<TblProduct> result = (await dbConnection.QueryAsync<TblProduct>(
"FetchProductTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return new List<TblProduct>();
}
}
public async Task<IEnumerable<RestockLevel>> 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<RestockLevel> result = (await dbConnection.QueryAsync<RestockLevel>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return new List<RestockLevel>();
}
}
public async Task<IEnumerable<TbStock>> 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<TbStock> result = (await dbConnection.QueryAsync<TbStock>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return new List<TbStock>();
}
}
public async Task<IEnumerable<UnitOfMeasure>> 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<UnitOfMeasure> result = (await dbConnection.QueryAsync<UnitOfMeasure>(
"FetchTableRows",
parameters,
commandType: CommandType.StoredProcedure)).AsList();
return result;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return new List<UnitOfMeasure>();
}
}
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<TblBrand> GetBrands(string a_brandKey = "")
{
throw new NotImplementedException();
}
public IEnumerable<TblCategory> GetCategories(string a_categoryKey = "")
{
throw new NotImplementedException();
}
public IEnumerable<ProductItem> GetLowstockItems()
{
throw new NotImplementedException();
}
public ProductItem GetProductById(string a_id)
{
throw new NotImplementedException();
}
public ProductItem GetProductByName(string name)
{
throw new NotImplementedException();
}
public IEnumerable<ProductItem> GetProducts(string a_productKey = "")
{
throw new NotImplementedException();
}
public string GetUnitName(string a_unitCode)
{
throw new NotImplementedException();
}
public IEnumerable<UnitOfMeasure> GetUnitofmeasures()
{
throw new NotImplementedException();
}
public void RefreshList()
{
throw new NotImplementedException();
}
}
}