public DefaultMenuRestaurant GetMultiDefaultRestaurantByCuisine(string cuisine)
{
Stopwatch stop = Stopwatch.StartNew();
var queryCollection = Query.NE("IsDeleted", true);
using (Restaurants restaurantsDb = new Restaurants())
{
MongoEntityRepositoryBase<DefaultMenuRestaurant> basicData =
new MongoEntityRepositoryBase<DefaultMenuRestaurant>(restaurantsDb.DB);
if (cuisine != null && cuisine.Length > 2)
{
var queryCuisine = Query.EQ("Cuisine", cuisine);
//var queryCuisines = Query.Matches("Cuisines", BsonRegularExpression.Create(new Regex(cuisine, RegexOptions.IgnoreCase)));
//var queryCollectionor = Query.Or(queryCuisine, queryCuisines);
var queryCuisinesCount = Query.Or(Query.Exists("Cuisines.1"));
queryCollection = Query.And(
queryCollection,
queryCuisine,
queryCuisinesCount
);
log.DebugFormat("[GetMultiDefaultRestaurantByCuisine] query exec={0}, cuisine={1}.", stop.ElapsedMilliseconds, cuisine);
}
var allRests = basicData.FindAs(queryCollection);
//List<Ingredient> ingredientsList = allAllIngredients.OrderBy(i => i.USDA_NDB_No).ToList();
List<DefaultMenuRestaurant> restaurantsList = allRests.ToList();
int restsCount = restaurantsList != null ? restaurantsList.Count : 0;
log.DebugFormat("[GetMultiDefaultRestaurantByCuisine] exec={0}, cuisine={1}, default menu restaurants count=[2].", stop.ElapsedMilliseconds, cuisine, restsCount);
if (restaurantsList.Count > 0) return restaurantsList[0];
else return null;
}
}