public List <ProductModel> GetProducts(string catID) { List <ProductModel> TList = null; try { string key = String.Format("Products_{0}", catID); TList = cache.Retrieve <List <ProductModel> >(key); if (TList == null) { DataTable dataTable = GetProductsDB(catID); TList = RepositoryHelper.ConvertToList <ProductModel>(dataTable); if (TList != null) { List <ImageModel> ImageList = null; foreach (var item in TList) { DataTable imageTable = GetImages(item.ProductID); ImageList = RepositoryHelper.ConvertToList <ImageModel>(imageTable); if (ImageList != null && ImageList.Count() > 0) { item.Image = ImageList.First <ImageModel>(); } } cache.Insert(key, TList); } } } catch (Exception) { throw; } return(TList); }
public ProductModel GetProduct(string prodId) { ProductModel product = null; List <ProductModel> TList = null; try { // we should be adding each product related to catId in cache // and here, we should be able to get a product in cache string key = String.Format("Product_{0}", prodId); product = cache.Retrieve <ProductModel>(key); if (product == null) { DataTable dataTable = GetProductDB(prodId); TList = RepositoryHelper.ConvertToList <ProductModel>(dataTable); List <ImageModel> ImageList = null; foreach (var item in TList) { DataTable imageTable = GetImages(item.ProductID); ImageList = RepositoryHelper.ConvertToList <ImageModel>(imageTable); if (ImageList != null && ImageList.Count() > 0) { item.Image = ImageList.First <ImageModel>(); } } // We should have only one item in the list product = TList.First <ProductModel>(); cache.Insert(key, product); } } catch (Exception) { throw; } return(product); }
public RegistrationModel GetCustomerInfo(string userName) { RegistrationModel Customer = null; List <RegistrationModel> TList = null; try { string key = String.Format("Customer_{0}", userName); Customer = cache.Retrieve <RegistrationModel>(key); if (Customer == null) { DataTable dataTable = GetCustomerDB(userName); TList = RepositoryHelper.ConvertToList <RegistrationModel>(dataTable); Customer = TList.First <RegistrationModel>(); cache.Insert(key, Customer); } } catch (Exception) { throw; } return(Customer); }