private void ParsePropertyValueToken(DishRecipe dishRecipe, JToken propertyValueToken) { ExtractValuesFromToken(propertyValueToken, out IList <JToken> values, out JTokenType valueType); switch (valueType) { case JTokenType.Integer: { String propertyName = propertyValueToken.Parent.Path; AddIntProperty(dishRecipe, propertyName, values); break; } case JTokenType.Object: { AddObjectProperty(dishRecipe, values); break; } default: { return; } } }
public void OpenWindow(MissionData missionData) { ContentContainer.SetActive(true); Mission = missionData; for (int i = 0; i < ClientDishes.Length; i++) { int dish = missionData.Dishes [i]; ClientDishes [i].text = dish.ToString(); Image[] stars = Stars(i); DishRecipe dishRecipe = Restaurant.instance.DishRecipes [dish]; foreach (var star in stars) { star.sprite = Player.instance.gameObject.GetComponent <Storage> ().StarSprites [0]; } for (int j = 0; j < dishRecipe.Level; j++) { stars [j].sprite = Player.instance.gameObject.GetComponent <Storage> ().StarSprites [1]; } int cost = dishRecipe.CostsByLevel [dishRecipe.Level - 1]; int additionalCost = cost - dishRecipe.CostsByLevel [0]; string dishCostString = "$" + cost; if (additionalCost > 0) { dishCostString += " (+$" + additionalCost + ")"; } GoldRewards [i].text = dishCostString; } string dropString = "Possible drop:\n"; foreach (var item in missionData.ItemRewards) { dropString += "- " + Restaurant.instance.ItemNames [item] + "\n"; } DropText.text = dropString; }
public void LevelUpDish(DishRecipe dishRecipe) { int[] currentCollection = dishRecipe.CurrentCollection(); foreach (var item in currentCollection) { ItemCounts [item]--; } dishRecipe.LevelUp(); OnRestaurantInfoChanged(); }
public void addDishRecipe(DishRecipe dish) { SqlConnection con; SqlCommand cmd; try { con = connect("DBConnectionString"); // create the connection } catch (Exception ex) { // write to log throw (ex); } String cStr = BuildInsertCommand(dish); // add tour ang getId of tour cmd = CreateCommand(cStr, con); // create the command try { Int32 recipeId = Convert.ToInt32(cmd.ExecuteScalar()); // execute the command for (int i = 0; i < dish.Ingredients.Length; i++) { try { cStr = BuildInsertCommand(recipeId, dish.Ingredients[i].Id); cmd = CreateCommand(cStr, con); // create the command cmd.ExecuteNonQuery(); // execute the command } catch (Exception ex) { throw (ex); } } } catch (Exception ex) { // write to log throw (ex); } finally { if (con != null) { // close the db connection con.Close(); } } }
public int Post([FromBody] DishRecipe d) { try { DishRecipe.addDishRecipe(d); return(1); } catch (Exception ex) { throw ex; } }
// POST api/<controller> public int Post([FromBody] DishRecipe dishRecipe) { try { DishRecipe.insertDishRecipe(dishRecipe); return(1); } catch (Exception ex) { throw ex; } }
private String BuildInsertCommand(DishRecipe dish) { String command; StringBuilder sb = new StringBuilder(); //use a string builder to create the dynamic string sb.AppendFormat("Values('{0}', '{1}', '{2}','{3}')", dish.Name, dish.Image, dish.CookingMethod, dish.Time); String prefix = "INSERT INTO Recipes " + "(name,image,cookingMethod,time) "; command = prefix + sb.ToString(); command += "SELECT SCOPE_IDENTITY()"; return(command); }
private DishRecipe MakeDishRecipeFromJObject(JObject jobject) { String recipeName = jobject.GetValue("Name")?.ToObject <String>() ?? String.Empty; DishRecipe dishRecipe = new DishRecipe(recipeName); JEnumerable <JToken> propertyTokens = jobject.Children(); foreach (JToken propertyToken in propertyTokens) { ParsePropertyValueToken(dishRecipe, propertyToken.First); } return(dishRecipe); }
private void AddObjectProperty(DishRecipe dishRecipe, IList <JToken> objectValues) { if (objectValues == null) { return; } foreach (JToken objectToken in objectValues) { JObject jobject = objectToken as JObject; String propertyName = jobject.First.First.ToObject <String>(); JToken valueToken = jobject.Last.First; ExtractValuesFromToken(valueToken, out IList <JToken> values, out JTokenType valueType); AddIntProperty(dishRecipe, propertyName, values); } }
public void FilterRecipes(int cuisine) { int startIndex = cuisine * 8; DishRecipe[] cuisineDishRecipes = new DishRecipe[Restaurant.instance.DishesInCuisine]; for (int i = 0; i < cuisineDishRecipes.Length; i++) { /*Debug.Log ("Start index: " + startIndex); * Debug.Log ("Cuisine dishes length: " + cuisineDishRecipes.Length); * Debug.Log ("Dishes in restaurant: " + Restaurant.instance.DishRecipes.Length);*/ cuisineDishRecipes [i] = Restaurant.instance.DishRecipes [startIndex + i]; } for (int i = 0; i < RecipeObjects.Length; i++) { recipeUIElements [i] = RecipeObjects[i].GetComponent <RecipeUIElement> (); recipeUIElements [i].dishRecipe = cuisineDishRecipes [i]; } foreach (var recipeUIElement in recipeUIElements) { recipeUIElement.UpdateElement(); } }
private void AddIntProperty(DishRecipe dishRecipe, String propertyName, IList <JToken> intValues) { ICondition condition = CreateConditionFromIntValues(intValues); dishRecipe.AddPropertyWithCondition(propertyName, condition); }
public List <DishRecipe> getDishRecipe() { SqlConnection con = null; SqlConnection con2 = null; try { con = connect("DBConnectionString"); // create a connection to the database using the connection String defined in the web config file String selectSTR = "select * from Recipes"; SqlCommand cmd = new SqlCommand(selectSTR, con); SqlCommand cmd2; // get a reader SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); // CommandBehavior.CloseConnection: the connection will be closed after reading has reached the end SqlDataReader dr2; // CommandBehavior.CloseConnection: the connection will be closed after reading has reached the end List <DishRecipe> list = new List <DishRecipe>(); while (dr.Read()) { // Read till the end of the data into a row DishRecipe d = new DishRecipe(); d.Id = (int)dr["id"]; d.Name = (string)dr["name"]; d.Image = (string)dr["image"]; d.Time = (int)dr["time"]; d.CookingMethod = (string)dr["CookingMethod"]; list.Add(d); } con.Close(); cmd.Connection.Close(); foreach (DishRecipe item in list) { con2 = connect("DBConnectionString"); // create a connection to the database using the connection String defined in the web config file con = connect("DBConnectionString"); // create a connection to the database using the connection String defined in the web config file selectSTR = "select I.name , I.calories , I.id , I.image from IngredientsRecipes as IR join Recipes as R on IR.recipeId=R.id join ingredients as I on I.ID=IR.ingredientId where IR.recipeId =" + item.Id; cmd2 = new SqlCommand(selectSTR, con2); dr2 = cmd2.ExecuteReader(CommandBehavior.CloseConnection); List <Ingredient> list2 = new List <Ingredient>(); while (dr2.Read()) { Ingredient ing = new Ingredient(); ing.Id = (int)dr2["id"]; ing.Name = (string)dr2["name"]; ing.Image = (string)dr2["image"]; ing.Calories = (int)dr2["calories"]; list2.Add(ing); } cmd2.Connection.Close(); con2.Close(); cmd.Connection.Close(); con.Close(); item.Ingredients = list2.ToArray(); } return(list); } catch (Exception ex) { // write to log throw (ex); } finally { if (con != null) { con.Close(); con2.Close(); } } }
public List <DishRecipe> Get() { return(DishRecipe.getAllRecipe()); }
public void InitializeFromData(RestaurantData data) { NotFirstTime = data.NotFirstTime; if (NotFirstTime) { Debug.Log("Should copy dishes from data"); dishRecipes = new DishRecipe[data.DishRecipes.Length]; data.DishRecipes.CopyTo(dishRecipes, 0); } else { Debug.Log("Making new dishes"); dishRecipes = new DishRecipe[40]; for (int i = 0; i < dishRecipes.Length; i++) { int cuisine = i / DishesInCuisine; dishRecipes [i] = new DishRecipe(i, 1, 5, cuisine, new int[5] { 10 + cuisine * 10, 20 + cuisine * 10, 30 + cuisine * 10, 40 + cuisine * 10, 50 + cuisine * 10 }); // бывает id 0 // Debug.Log((i / DishesInCuisine).ToString()); } } Tiles = FloorContainer.GetComponentsInChildren <Tile>(); if (data.TileTypes.Length > 0) { for (int i = 0; i < data.TileTypes.Length; i++) { Tiles [i].TileSpriteIndex = data.TileSpriteIndexes [i]; Tiles [i].ChangeTile(data.TileTypes [i]); } } data.ItemCounts.CopyTo(ItemCounts, 0); Session = data.Session; Prestige = data.Prestige; PrestigeLevel = data.PrestigeLevel; LastTime = data.LastTime; energy = data.Energy; gold = data.Gold; raidTickets = data.RaidTickets; starmoney = data.Starmoney; stars = data.Stars; for (int i = 0; i < data.BuildingDatas.Count; i++) { GameObject buildingObject = Instantiate(Builder.SBuildingPrefabs[data.BuildingDatas[i].TypeId]) as GameObject; // Выглядит стремно, но пока работает верно buildingObject.GetComponent <Building> ().InitializeFromData(data.BuildingDatas [i]); Buildings.Add(buildingObject.GetComponent <Building> ()); CurrentBuildings [data.BuildingDatas[i].TypeId]++; // не очень изящно, надо подумать, как поменять } if (data.ClientDatas.Count > 0) { clientTimer = 1.0f; for (int i = 0; i < data.ClientDatas.Count; i++) { GameObject clientObject = Instantiate(ClientPrefab) as GameObject; clientObject.GetComponent <Client> ().InitializeFromData(data.ClientDatas [i]); CurrentClients.Add(clientObject.GetComponent <Client> ()); } } System.TimeSpan ts = System.DateTime.Now.Subtract(LastTime); int seconds = (int)ts.TotalSeconds; if (NotFirstTime && seconds > 0) { SkipTime(seconds); } if (Player.instance.HasWon) { Player.instance.HasWon = false; stars += Player.instance.StarCount; AddGold(Player.instance.GoldFromMission); List <int> itemsWon = new List <int> (); for (int i = 0; i < Player.instance.MyMission.ItemRewards.Length; i++) { if (Random.Range(0.0f, 1.0f) < Player.instance.MyMission.ItemChances[i]) { AddItem(Player.instance.MyMission.ItemRewards [i]); itemsWon.Add(Player.instance.MyMission.ItemRewards [i]); } } Debug.Log(itemsWon); OnMissionEnded(Player.instance.GoldFromMission, itemsWon); } OnRestaurantInfoChanged(); NotFirstTime = true; }
// GET api/<controller> public IEnumerable <DishRecipe> Get() { return(DishRecipe.getDishRecipe()); }
/// <summary> /// Updates a Dish and its recipes in the database. /// </summary> /// <param name="dish">Requires a complete DishDTO including all of its recipes.</param> /// <returns>True: if successful</returns> public async Task <bool> UpdateDish(UpdateDishDTO dish) { // TODO: Complete this method and write a (few?) test(s) to confirm its functionality. // Completing this method may require usage of other services // A few things to remember with the update: // 1. When updating the dish, the recipe could change. // 2. A recipe consists of ingredients, which could also change // Get the dish // Update the items in the DB with the new DTO // Update the dish with the new recipes // Update the new recipes with new ingredients // If successful return true // If unsuccessful return false // Get the Dish from the database var dishFromDB = await _context.Dishes.Where(x => x.Name == dish.Name).FirstOrDefaultAsync(); if (dishFromDB == null) { return(false); } // Update its basic information dishFromDB.Name = dish.Name; dishFromDB.DishType = dish.Type; // Update the database _context.Entry(dishFromDB).State = EntityState.Modified; // Find all join entities between this dish and recipes var deleteTheseRecipes = await _context.DishRecipes.Where(x => x.DishId == dishFromDB.Id).ToListAsync(); foreach (var recipe in deleteTheseRecipes) { // Delete those references _context.Entry(recipe).State = EntityState.Deleted; } foreach (var recipe in dish.Recipes) { // Build a new DishRecpie join entity var newRecpieJoin = new DishRecipe { DishId = dish.Id, RecipeId = recipe.Id }; // Add that entity to the database _context.Entry(newRecpieJoin).State = EntityState.Added; // Find all join entities between this Recipe and its ingredients var deleteTheseIngredientsFromTheRecipe = await _context.RecipeIngredients.Where(x => x.RecipeId == recipe.Id).ToListAsync(); foreach (var ingredient in deleteTheseIngredientsFromTheRecipe) { // Delete those references _context.Entry(ingredient).State = EntityState.Deleted; } foreach (var ingredient in recipe.Ingredients) { // Build a new RecipeIngredient join entity var newIngredientJoin = new RecipeIngredients { RecipeId = recipe.Id, IngredientId = ingredient.Id }; // Add that entity into the database _context.Entry(newIngredientJoin).State = EntityState.Added; } } // Save All the Changes await _context.SaveChangesAsync(); return(true); }