public List <AllRecipes> SelectAll() { List <AllRecipes> allRecipesList = new List <AllRecipes>(); string sqlConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; using (SqlConnection conn = new SqlConnection(sqlConnectionString)) { conn.Open(); using (SqlCommand cmd = new SqlCommand("Recipes_SelectAll", conn)) { cmd.CommandType = CommandType.StoredProcedure; SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { AllRecipes model = RecipesMapper(reader); allRecipesList.Add(model); } } conn.Close(); } return(allRecipesList); }
void Start() { instance = this; AllRecipes.Enqueue(new Recipe(1, 0, 0, 0)); AllRecipes.Enqueue(new Recipe(1, 1, 0, 0)); AllRecipes.Enqueue(new Recipe(2, 0, 1, 0)); AllRecipes.Enqueue(new Recipe(0, 1, 2, 0)); AllRecipes.Enqueue(new Recipe(1, 2, 3, 0)); AllRecipes.Enqueue(new Recipe(2, 2, 0, 1)); AllRecipes.Enqueue(new Recipe(4, 3, 4, 1)); AllRecipes.Enqueue(new Recipe(4, 4, 2, 2)); AllRecipes.Enqueue(new Recipe(5, 5, 4, 2)); AllSpawnOdds.Enqueue(new SpawnOdds(1f, 0f, 0f, 0f)); AllSpawnOdds.Enqueue(new SpawnOdds(.5f, .5f, 0f, 0f)); AllSpawnOdds.Enqueue(new SpawnOdds(.4f, .2f, .4f, 0f)); AllSpawnOdds.Enqueue(new SpawnOdds(.3f, .3f, .4f, 0f)); AllSpawnOdds.Enqueue(new SpawnOdds(.3f, .3f, .4f, 0f)); AllSpawnOdds.Enqueue(new SpawnOdds(.2f, .2f, .2f, .4f)); AllSpawnOdds.Enqueue(new SpawnOdds(.1f, .4f, .3f, .2f)); AllSpawnOdds.Enqueue(new SpawnOdds(.1f, .4f, .3f, .2f)); AllSpawnOdds.Enqueue(new SpawnOdds(.3f, .2f, .3f, .2f)); GetNextRecipe(); UpdateRecipeText(); for (int i = 0; i < SpawnPointsContainer.transform.childCount - 1; i++) { SpawnPoints.Add(SpawnPointsContainer.transform.GetChild(i)); } StartCoroutine(Spawner()); }
public void RefreshRecipes() { AllRecipes.Clear(); foreach (var item in _dataSvc.GetAllRecipes()) { AllRecipes.Add(item); } }
private AllRecipes RecipesMapper(SqlDataReader reader) { AllRecipes model = new AllRecipes(); int index = 0; model.Id = reader.GetInt32(index++); model.Name = reader.GetString(index++); model.SystemFileName = reader.GetString(index++); return(model); }
public RecipeViewModel(INavigation navigation, IUserDialogs dialogs, IPopupNavigation popupNavigation, IApiService apiService) { _apiService = apiService; Navigation = navigation; Dialogs = dialogs; bool canFetchRecipes = false; FetchRecipesCommand = new Command(async() => { CanInitiateNewFetchRecipes(false); try { Dialogs?.ShowLoading("Fetching recipes for you..."); if (Connectivity.NetworkAccess == NetworkAccess.Internet) { try { if (PageSize == 100) //max page size reached { Dialogs?.HideLoading(); await Dialogs?.AlertAsync("The end of the list has been reached :(", "Notice", "OK"); return; } var RecipesRetrieved = await _apiService.GetAllRecipes(PageSize); if (RecipesRetrieved != null) { if (RecipesRetrieved.results.Count > 0) { foreach (var data in RecipesRetrieved.results) { AllRecipes.Add(data); } } PageSize++; Items = (AllRecipes.Count) - 1; Dialogs?.HideLoading(); } else { Dialogs?.HideLoading(); await Dialogs?.AlertAsync("No data found!. Please try again later.", "Error", "OK"); } } catch (ApiException ex) { Dialogs?.HideLoading(); popupNavigation?.PopAsync(); await Dialogs?.AlertAsync(ex.Content, ex.Name, "OK"); } catch (Exception ex) { Dialogs?.HideLoading(); await Dialogs?.AlertAsync("An unexpected error has occurred. Please try again.", "Error", "OK"); Debug.WriteLine(ex); } } else { Dialogs?.HideLoading(); popupNavigation?.PopAsync(); await Dialogs?.AlertAsync("You seem to be offline. Please connect to the Wi-Fi and try again.", "Error", "OK"); } } catch (Exception e) { Debug.WriteLine(e); Dialogs?.HideLoading(); } CanInitiateNewFetchRecipes(true); }, () => canFetchRecipes); void CanInitiateNewFetchRecipes(bool value) { canFetchRecipes = value; ((Command)FetchRecipesCommand).ChangeCanExecute(); } }