/// <summary> /// To get list of menuitems in the Restaurant /// </summary> /// <param name="restaurantId"></param> /// <param name="searchText"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns>IEnumerable<RestaurantMenu></returns> public async Task <IEnumerable <RestaurantMenu> > GetRestaurantMenusAsync(int restaurantId, string searchText = null, int pageIndex = 0, int pageSize = 0) { LoggerManager.InfoLog(string.Format("Executing service to get the menu list of restaurant - {0}", restaurantId)); IEnumerable <RestaurantMenu> searchList = null; LoggerManager.DebugLog("Establishing connection with Redis cache"); if (restaurantId > 0) { //Read Redis Cache IRedisList <RestaurantMenu> menuList = getRedisCacheObject(_configuration["CacheKeyPrefix"] + restaurantId); //Load Redis Cache if (menuList == null || menuList.Count == 0) { LoggerManager.DebugLog("Loading items into the Redis cache"); menuList = await LoadMenuToRedisCache(restaurantId.ToString()); } //Search cache for menuitem and return search list if (menuList != null) { if (!String.IsNullOrEmpty(searchText)) { LoggerManager.InfoLog(string.Format("Searching for menu items with text - {0}", searchText)); searchList = menuList.Where <RestaurantMenu>(menuitem => menuitem.MenuItemName.Contains(searchText.ToUpper())); } else { searchList = menuList.AsEnumerable <RestaurantMenu>(); } } } if (pageIndex > 0 && pageSize > 0 && searchList != null && searchList.Count() > 0) { searchList = searchList.Skip(pageSize * (pageIndex - 1)).Take(pageSize); LoggerManager.InfoLog(string.Format("Returning paged menu items of page index - {0} and of size {1}", pageIndex, pageSize)); if (searchList == null || searchList.Count() <= 0) { throw new Exception("End of Page"); } } return(searchList); }