public static List<UserMealProfile> GetAllUserMealProfiles() { log.DebugFormat("[GetAllUserMealProfiles]."); using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<UserMealProfile> basicData = new MongoEntityRepositoryBase<UserMealProfile>(restaurantsDb.DB); var allRestaurants = basicData.GetAll(); List<UserMealProfile> selected = allRestaurants.ToList(); return selected; } }
public List<SpontaneousUserModel> GetAllUsersData(bool withMenu = true) { log.DebugFormat("[GetAllUsersData]."); using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<SpontaneousUserModel> basicData = new MongoEntityRepositoryBase<SpontaneousUserModel>(restaurantsDb.DB); var allRestaurants = basicData.GetAll(); List<SpontaneousUserModel> selected = allRestaurants.ToList(); return selected; } }
//[TestMethod] public void AddExtendedDataTest() { //arrange var testdb = new MongoDBForTest().DB; MongoEntityRepositoryBase<ProductBasicData> basicData = new MongoEntityRepositoryBase<ProductBasicData>(testdb); List<ProductBasicData> products = basicData.GetAll().ToList(); ProductFetcher extendDataFetcher = new ProductFetcher(); ProductDataExtendedDataBuilder builder = new ProductDataExtendedDataBuilder(); //act foreach (var product in products) { string crawledHtml = extendDataFetcher.GetProductExtendedData(product); product.ExtendedData = builder.Build(crawledHtml); } }
private static void UpdateExtendedData() { CrawledProducts productsDb = new CrawledProducts(); MongoEntityRepositoryBase<ProductBasicData> basicData = new MongoEntityRepositoryBase<ProductBasicData>(productsDb.DB); List<ProductBasicData> products = basicData.GetAll().ToList(); log.InfoFormat("Found {0} products for fetching", products.Count); //foreach (var item in allFiles) //{ //string html = File.ReadAllText(item); //ProductBasicDataFetcher fetcher = new ProductBasicDataFetcher(html); ProductFetcher extendDataFetcher = new ProductFetcher(); ProductDataExtendedDataBuilder builder = new ProductDataExtendedDataBuilder(); //act //products = fetcher.FetchProducts(); int count = 0; foreach (var product in products) { try { if (product.ExtendedData != null) continue; //product.Category = item; string crawledHtml = extendDataFetcher.GetProductExtendedData(product); product.ExtendedData = builder.Build(crawledHtml); basicData.Update(product); count++; int nutritionTableCount = 0; if (product.ExtendedData != null && product.ExtendedData.NutritionTable != null) { nutritionTableCount = product.ExtendedData.NutritionTable.Count; log.InfoFormat("Product fetched = {0} Product Name = {2} nutritionTableCount = {1}.", count, nutritionTableCount, product.ProductName); } } catch (Exception ex) { log.WarnFormat("Problem on updating extended data product={0}, ex={1}.", product, ex); } System.Threading.Thread.Sleep(400); } }
public RecipeModel GetRecipeByPartialName(string partialName) { if (partialName == null) return null; using (CrawledRecipes recipesDb = new CrawledRecipes()) { MongoEntityRepositoryBase<RecipeBasicData> basicData = new MongoEntityRepositoryBase<RecipeBasicData>(recipesDb.DB); var allRecipes = basicData.GetAll(); List<RecipeBasicData> selected = allRecipes.Where(p => p.Name != null && p.Name.Contains(partialName)).ToList(); List<RecipeModel> recipeList = selected.ToRecipeModel(); if (recipeList != null && recipeList.Count > 0) { return recipeList.FirstOrDefault(p => p.Name.Length == recipeList.Max(lenght => lenght.Name.Length)); } else { return null; } } }
public ProductCatalogViewModel GetProductByLastCharsOfBarcode(string barcode) { using (CrawledProducts productsDb = new CrawledProducts()) { MongoEntityRepositoryBase<ProductBasicData> basicData = new MongoEntityRepositoryBase<ProductBasicData>(productsDb.DB); var allProducts = basicData.GetAll(); List<ProductBasicData> selected = allProducts.Where(c => barcode.EndsWith(c.ProductId)).ToList(); List<ProductCatalogViewModel> productList = selected.ToProductCatalogModel(); if (productList != null && productList.Count > 0) { return productList.FirstOrDefault(c => c.ProductId.Length == productList.Max(lenght => lenght.ProductId.Length)); } else { return null; } } }
/// <summary> /// Same to GetPagedRestaurants but sorting performed not by MongoDB query /// </summary> /// <param name="page"></param> /// <param name="pageSize"></param> /// <param name="sortedBy"></param> /// <returns></returns> public PagedList<RestaurantModel> GetPagedRestaurantsSortedNotByMongo(int? page, int pageSize, SortByEnum sortedBy) { log.DebugFormat("[GetPagedRestaurantsSortedNotByMongo] page={0}, searchText={1}.", page ?? 0, pageSize); if (sortedBy != null && sortedBy == SortByEnum.RestaurantDishCount) { using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<RestaurantBasicData> basicData = new MongoEntityRepositoryBase<RestaurantBasicData>(restaurantsDb.DB); int skip = (page ?? 0) * pageSize; var restCount = (int)basicData.Count(); PagedList<RestaurantModel> returnList = new PagedList<RestaurantModel>(); IEnumerable<RestaurantBasicData> allRestaurants = basicData.GetAll();; if (allRestaurants == null) return null; List<RestaurantBasicData> selected = allRestaurants.ToList(); List<RestaurantModel> restaurantList = selected.ToRestaurantModel(false); returnList.Entities = restaurantList.OrderBy(r => r.DishCount).Reverse().Skip(skip).Take(pageSize).ToList(); returnList.CurrentPage = page ?? 0; returnList.TotalPages = restCount / pageSize; returnList.SortedBy = sortedBy; return returnList; } } else { log.WarnFormat("[GetPagedRestaurantsSortedNotByMongo] sortedBy parameter is null or uknown."); return null; } }
public PagedList<RestaurantModel> GetPagedRestaurants(int? page, int pageSize, SortByEnum sortedBy) { log.DebugFormat("[GetPagedRestaurants] page={0}, searchText={1}.", page ?? 0, pageSize); using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<RestaurantBasicData> basicData = new MongoEntityRepositoryBase<RestaurantBasicData>(restaurantsDb.DB); int skip = (page ?? 0) * pageSize; var restCount = (int)basicData.Count(); PagedList<RestaurantModel> returnList = new PagedList<RestaurantModel>(); IEnumerable<RestaurantBasicData> allRestaurants = null; if (sortedBy == null || sortedBy == 0) { allRestaurants = basicData.GetAll(); } else { string sortByStr = null; switch (sortedBy) { case SortByEnum.RestaurantName: sortByStr = "Name"; break; case SortByEnum.RestaurantCuisine: sortByStr = "Cuisines.0"; break; case SortByEnum.RestaurantCreatedAt: sortByStr = "CreatedAt"; break; case SortByEnum.RestaurantUpdatedAt: sortByStr = "UpdatedAt"; break; case SortByEnum.Uknown: break; case SortByEnum.RestaurantDishCount: sortByStr = "DishCount"; break; case SortByEnum.RestaurantSource: sortByStr = "Source"; break; } if (sortByStr != null && sortByStr != "DishCount") { allRestaurants = basicData.GetAllSortedBy(sortByStr); returnList.SortedBy = sortedBy; } } if (allRestaurants == null) return null; IEnumerable<RestaurantBasicData> restsPage; if (pageSize == -1) restsPage = allRestaurants; else restsPage = allRestaurants.Skip(skip).Take(pageSize); List<RestaurantBasicData> selected = restsPage.ToList(); List<RestaurantModel> restaurantList = selected.ToRestaurantModel(false); returnList.CurrentPage = page ?? 0; returnList.TotalPages = restCount / pageSize; returnList.Entities = restaurantList; return returnList; } }
public List<RestaurantBasicData> GetChainRestaurantsBasicByName(string name) { if (name == null) return null; List<RestaurantBasicData> chain = null; using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<RestaurantBasicData> basicData = new MongoEntityRepositoryBase<RestaurantBasicData>(restaurantsDb.DB); var allRestaurants = basicData.GetAll(); chain = allRestaurants.Where(p => p.Name != null && p.Name.Contains(name)).ToList(); } return chain; }
public List<RestaurantBasicData> GetAllRestaurantsBasic() { log.DebugFormat("[GetAllRestaurantsBasic]."); using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<RestaurantBasicData> basicData = new MongoEntityRepositoryBase<RestaurantBasicData>(restaurantsDb.DB); var allRestaurants = basicData.GetAll(); //List<RestaurantBasicData> selected = allRestaurants.ToList(); List<RestaurantBasicData> selected = allRestaurants.OrderBy(r => r.Name).ToList(); return selected; } }
public List<OperatorMap> GetAllOperatorMaps() { log.InfoFormat("[GetAllOperatorMaps]."); using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<OperatorMap> basicData = new MongoEntityRepositoryBase<OperatorMap>(restaurantsDb.DB); var allOperatorMaps = basicData.GetAll(); //List<RestaurantBasicData> selected = allRestaurants.ToList(); List<OperatorMap> selected = allOperatorMaps.OrderBy(r => r.Name).ToList(); return selected; } }
public List<RestaurantOsm> GetAllRestaurantsOsm() { try { log.DebugFormat("[GetAllRestaurantsOsm]."); //using (ImportedRestaurants restaurantsDb = new ImportedRestaurants()) using (FinlandSwedenOSMRestaurants restaurantsDb = new FinlandSwedenOSMRestaurants()) { MongoEntityRepositoryBase<RestaurantOsm> basicData = new MongoEntityRepositoryBase<RestaurantOsm>(restaurantsDb.DB); var allRestaurants = basicData.GetAll(); List<RestaurantOsm> selected = allRestaurants.ToList(); return selected; } } catch (Exception e) { log.ErrorFormat("[GetAllRestaurantsOsm] Exception={0}.", e); return null; } }
public List<DefaultMenuRestaurant> GetAllDefaultMenuRestaurants() { log.DebugFormat("[GetAllDefaultMenuRestaurants]."); using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<DefaultMenuRestaurant> basicData = new MongoEntityRepositoryBase<DefaultMenuRestaurant>(restaurantsDb.DB); var allDefaultMenuRestaurants = basicData.GetAll(); //List<RestaurantBasicData> selected = allRestaurants.ToList(); List<DefaultMenuRestaurant> selected = allDefaultMenuRestaurants.OrderBy(r => r.Name).ToList(); if (selected.Count > 0) return selected; return null; } }
public List<GeneralDish> GetAllGeneralDishes() { log.DebugFormat("[GetAllGeneralDishes]"); using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<GeneralDish> basicData = new MongoEntityRepositoryBase<GeneralDish>(restaurantsDb.DB); var allDishes = basicData.GetAll(); if (allDishes != null) { List<GeneralDish> returnList = allDishes.ToList(); return returnList; } return null; } }
public List<CouponType> GetAllCoupons() { log.DebugFormat("[GetAllCoupons]"); using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<CouponType> basicData = new MongoEntityRepositoryBase<CouponType>(restaurantsDb.DB); var allCoupons = basicData.GetAll(); if (allCoupons != null) { List<CouponType> returnList = allCoupons.ToList(); return returnList; } return null; } }
public NutritionType GetNutritionTypeByNo(int nutr_No) { log.InfoFormat("[GetNutritionTypeByNo] nutr_No={0}.", nutr_No); NutritionType returnValue; try { using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<NutritionType> basicData = new MongoEntityRepositoryBase<NutritionType>(restaurantsDb.DB); var allNutritionType = basicData.GetAll(); returnValue = allNutritionType.FirstOrDefault(n => n.USDA_Nutr_No != null && n.USDA_Nutr_No == nutr_No); } } catch (Exception e) { log.ErrorFormat("[GetNutritionTypeByNo] Exception={0}", e); returnValue = null; } return returnValue; }
public int GetCountOfAllIngredients() { //NutritionType returnValue; try { using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<Ingredient> basicData = new MongoEntityRepositoryBase<Ingredient>(restaurantsDb.DB); var allAllIngredients = basicData.GetAll(); List<Ingredient> ingredientsList = allAllIngredients.ToList(); log.InfoFormat("[GetCountOfAllIngredients] Count of all ingredients in DB = {0}.", ingredientsList.Count); return ingredientsList.Count; } } catch (Exception e) { log.ErrorFormat("[GetAllIngredients] Exception={0}", e); return -1; } }
public RestaurantModel GetRestaurantByName(string name) { if (name == null) return null; using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<RestaurantBasicData> basicData = new MongoEntityRepositoryBase<RestaurantBasicData>(restaurantsDb.DB); var allRestaurants = basicData.GetAll(); List<RestaurantBasicData> selected = allRestaurants.Where(p => p.Name != null && p.Name.Contains(name)).ToList(); List<RestaurantModel> restaurantList = selected.ToRestaurantModel(); if (restaurantList != null && restaurantList.Count > 0) { return restaurantList.FirstOrDefault(p => p.Name.Length == restaurantList.Max(lenght => lenght.Name.Length)); } else { return null; } } }
public List<RestaurantModel> GetAllRestaurants(bool withMenu=true) { log.DebugFormat("[GetAllRestaurants]."); using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<RestaurantBasicData> basicData = new MongoEntityRepositoryBase<RestaurantBasicData>(restaurantsDb.DB); var allRestaurants = basicData.GetAll(); List<RestaurantBasicData> selected = allRestaurants.ToList(); //List<RestaurantBasicData> selected = allRestaurants.OrderBy(r => r.UpdatedAt).Reverse().ToList(); //List<RestaurantBasicData> selected = allRestaurants.OrderBy(r => r.Name).ToList(); List<RestaurantModel> restaurantList = selected.ToRestaurantModel(withMenu); return restaurantList; } }
public List<GeneralDish> GetAllGeneralDishesOrderBy() { log.DebugFormat("[GetAllGeneralDishes]"); using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<GeneralDish> basicData = new MongoEntityRepositoryBase<GeneralDish>(restaurantsDb.DB); var allDishes = basicData.GetAll(); if (allDishes != null) { List<GeneralDish> returnList = allDishes.OrderBy(i => i.Dish.OverrideIngredients[0].USDA_NDB_No).ToList(); return returnList; } return null; } }
public List<RestaurantModel> GetAllRestaurants() { log.DebugFormat("[GetAllRestaurants]."); using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<RestaurantBasicData> basicData = new MongoEntityRepositoryBase<RestaurantBasicData>(restaurantsDb.DB); var allRestaurants = basicData.GetAll(); List<RestaurantBasicData> selected = allRestaurants.ToList(); List<RestaurantModel> restaurantList = selected.ToRestaurantModel(); return restaurantList; } }
public List<Ingredient> GetAllIngredients() { log.InfoFormat("[GetAllIngredients]."); try { using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<Ingredient> basicData = new MongoEntityRepositoryBase<Ingredient>(restaurantsDb.DB); var allAllIngredients = basicData.GetAll(); List<Ingredient> ingredientsList = allAllIngredients.OrderBy(i => i.USDA_NDB_No).ToList(); int count = ingredientsList != null ? ingredientsList.Count : 0; log.InfoFormat("[GetAllIngredients] Count={0}.", count); return ingredientsList; } } catch (Exception e) { log.ErrorFormat("[GetAllIngredients] Exception={0}", e); return null; } }
public static List<UserMealProfile> GetUserMealProfilesByDateRange(DateTime startDate, DateTime endDate) { try { if (startDate <= endDate) { log.DebugFormat("[GetUserMealProfilesByDateRange] startDate={0}, endDate={1}.", startDate, endDate); using (Restaurants restaurantsDb = new Restaurants()) { MongoEntityRepositoryBase<UserMealProfile> basicData = new MongoEntityRepositoryBase<UserMealProfile>(restaurantsDb.DB); //temp for debuging var allMealProfile = basicData.GetAll().ToList(); var queryCollection = Query.NE("IsDeleted", true); var queryFromDate = Query.GT("CreatedAt", startDate); var queryToDate = Query.LTE("CreatedAt", endDate); queryCollection = Query.And( queryCollection, queryFromDate, queryToDate ); var foundMealProfiles = basicData.FindAs(queryCollection, 0).OrderBy(r => r.CreatedAt).ToList(); return foundMealProfiles; } } else { log.WarnFormat("[GetUserMealProfilesByDateRange] Wrong date range."); return null; } } catch (Exception e) { log.ErrorFormat("[GetUserMealProfilesByDateInterval] Error: Exception={0}.", e.Message); return null; } }