using System.Collections.Generic; using System.Collections.ObjectModel; using Database.Models; using Database.Repository; namespace Pos.Service { public static class CacheService { private static bool _invalidEmployee = false; private static bool _invalidProductGroup = false; private static List _employees; private static List _productGroups; public static void Invalidate() { _invalidEmployee = true; _invalidProductGroup = true; } public static ObservableCollection GetEmployee() { ObservableCollection obsEmployees = new ObservableCollection(); if (_invalidEmployee) { EmployeeRepository employeeRepository = new EmployeeRepository(); _employees = employeeRepository.GetAll(); foreach (EmployeeEntity employee in _employees) { obsEmployees.Add(employee); } _invalidEmployee = false; } return obsEmployees; } public static ObservableCollection GetProductGroupsIncludeProducts() { ObservableCollection obsProductGroups = new ObservableCollection(); if(_invalidProductGroup) { ProductGroupRepository productGroupRepository = new ProductGroupRepository(); _productGroups = productGroupRepository.GetAll(); _invalidProductGroup = false; foreach (ProductGroupEntity productGroup in _productGroups) { obsProductGroups.Add(productGroup); } } return obsProductGroups; } } }