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.
203 lines
7.1 KiB
203 lines
7.1 KiB
using Biskilog_Accounting.Shared.CustomModels;
|
|
using Biskilog_Accounting.Shared.Interfaces;
|
|
using System.Text.Json;
|
|
using Biskilog_Accounting.Shared.POSModels;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Biskilog_Accounting.Client.Repos
|
|
{
|
|
public class ProductRepository : IProduct
|
|
{
|
|
private IEnumerable<ProductItem> m_products;
|
|
private IEnumerable<Unitofmeasure> m_units;
|
|
private IEnumerable<Tblbrand> m_brands;
|
|
private IEnumerable<Tblcategory> m_categories;
|
|
private readonly HttpClient m_http;
|
|
|
|
public event EventHandler ProductsChanged;
|
|
public event EventHandler UnitsChanged;
|
|
public event EventHandler BrandsChanged;
|
|
public event EventHandler CategoriesChanged;
|
|
|
|
public ProductRepository(HttpClient a_http)
|
|
{
|
|
m_products = new List<ProductItem>();
|
|
m_units = new List<Unitofmeasure>();
|
|
m_brands = new List<Tblbrand>();
|
|
m_categories = new List<Tblcategory>();
|
|
m_http = a_http;
|
|
}
|
|
public async Task FetchProducts()
|
|
{
|
|
var response = await m_http.GetAsync($"api/products/fetch");
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var jsonContent = await response.Content.ReadAsStringAsync();
|
|
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
|
|
var products = JsonSerializer.Deserialize<List<ProductItem>>(jsonContent, options);
|
|
m_products = products;
|
|
ProductsChanged?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
|
|
public ProductItem GetProductById(string a_id)
|
|
{
|
|
if (m_products.Count() > 0)
|
|
{
|
|
return m_products.First(i => i.Product.Pcode == a_id);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public ProductItem GetProductByName(string name)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public IEnumerable<ProductItem> GetProducts(string a_productKey)
|
|
{
|
|
a_productKey = Regex.Replace(a_productKey, @"\s", "").ToLower();
|
|
return m_products.Where(p => Regex.Replace(p.Product!.ProductName!, @"\s", "").ToLower().StartsWith(a_productKey) ||
|
|
Regex.Replace(p.Product!.Pcode!, @"\s", "").ToLower().StartsWith(a_productKey) ||
|
|
Regex.Replace(p.Product!.Pdesc!, @"\s", "").ToLower().StartsWith(a_productKey));
|
|
}
|
|
|
|
public void RefreshList()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public IEnumerable<Unitofmeasure> GetUnitofmeasures()
|
|
{
|
|
return m_units;
|
|
}
|
|
|
|
public async Task FetchUnits()
|
|
{
|
|
var response = await m_http.GetAsync($"api/products/units");
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var jsonContent = await response.Content.ReadAsStringAsync();
|
|
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
|
|
var units = JsonSerializer.Deserialize<List<Unitofmeasure>>(jsonContent, options);
|
|
m_units = units;
|
|
UnitsChanged?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
|
|
public string GetUnitName(string a_unitCode)
|
|
{
|
|
return m_units?.FirstOrDefault(u => u.UnitCode == a_unitCode)?.Unitname;
|
|
}
|
|
|
|
public IEnumerable<Tblbrand> GetBrands(string a_brandKey = "")
|
|
{
|
|
a_brandKey = Regex.Replace(a_brandKey, @"\s", "").ToLower();
|
|
return m_brands.Where(b => Regex.Replace(b.Id, @"\s", "").ToLower().StartsWith(a_brandKey) ||
|
|
Regex.Replace(b.Brand!, @"\s", "").ToLower().StartsWith(a_brandKey));
|
|
}
|
|
|
|
public IEnumerable<Tblcategory> GetCategories(string a_categoryKey = "")
|
|
{
|
|
a_categoryKey = Regex.Replace(a_categoryKey, @"\s", "").ToLower();
|
|
return m_categories.Where(c => Regex.Replace(c.Id, @"\s", "").ToLower().StartsWith(a_categoryKey) ||
|
|
Regex.Replace(c.Category!, @"\s", "").ToLower().StartsWith(a_categoryKey));
|
|
}
|
|
|
|
public async Task FetchBrands()
|
|
{
|
|
var response = await m_http.GetAsync($"api/products/brands");
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var jsonContent = await response.Content.ReadAsStringAsync();
|
|
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
|
|
var brands = JsonSerializer.Deserialize<List<Tblbrand>>(jsonContent, options);
|
|
m_brands = brands;
|
|
BrandsChanged?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
|
|
public async Task FetchCategories()
|
|
{
|
|
var response = await m_http.GetAsync($"api/products/categories");
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
var jsonContent = await response.Content.ReadAsStringAsync();
|
|
var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
|
|
var categories = JsonSerializer.Deserialize<List<Tblcategory>>(jsonContent, options);
|
|
m_categories = categories;
|
|
CategoriesChanged?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
|
|
public IEnumerable<ProductItem> GetLowstockItems()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task FetchLowStockProducts()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task SyncProducts(List<Tblproduct> a_item)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task SyncInventory(List<Tblinventory> a_item)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task SyncInventoryEntries(List<Tblinventoryentry> a_item)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task SyncPriceChanges(List<Tblpricechange> a_items)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task SyncProductAltUnit(List<Productaltunit> a_items)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task SyncRestockAsync(List<Restocklevel> a_items)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task SyncUnitOfMeasureAsync(List<Unitofmeasure> a_items)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task SyncStockAsync(List<Tbstock> a_items)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task SyncBrandsAsync(List<Tblbrand> a_items)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task SyncCategoriesAsync(List<Tblcategory> a_items)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public DateTime GetLastSyncDate(string a_tablename)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void SetLastSyncDate(string a_tableName, DateTime a_timestamp)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|
|
|