public IActionResult RecipeBrewing() { PotionRecipeCreationViewModel prcvm = new PotionRecipeCreationViewModel(); prcvm.Recipes = repo.Recipes; return(View(prcvm)); }
public Tests() { frepo = new FakeRepository(); home = new HomeController(frepo); i1 = new Ingredient { IngID = 0, IngPicture = "nether.png", IngName = "NetherWart", IngDescription = "The basics of every potion.", IngStock = 250 }; i2 = new Ingredient { IngID = 1, IngPicture = "sugar.png", IngName = "Sugar", IngDescription = "Sweet.", IngStock = 50 }; i3 = new Ingredient { IngID = 2, IngPicture = "blaze.png", IngName = "Blaze Powder", IngDescription = "Hot to the touch.", IngStock = 50 }; p1 = new Potion { PotionID = 0, PotionName = "Potion of Swiftness", PotionDescription = "Makes the user run with godspeed", PIng1 = i1, PIng2 = i2, PIng3 = i2, PotionStock = 1 }; p2 = new Potion { PotionID = 1, PotionName = "Potion of Strength", PotionDescription = "Gives the strength of the mightiest warrior", PIng1 = i1, PIng2 = i3, PIng3 = i3, PotionStock = 1 }; p3 = new Potion { PotionID = 2, PotionName = "Potion of Coolness", PotionDescription = "Makes you really cool", PIng1 = i1, PIng2 = i2, PIng3 = i3, PotionStock = 1 }; r1 = new Recipe { RecipeID = 0, RPotionName = "Potion of Swiftness", RPotionDesc = "Makes the user run with godspeed", RIng1 = i1, RIng2 = i2, RIng3 = i2 }; r2 = new Recipe { RecipeID = 1, RPotionName = "Potion of Strength", RPotionDesc = "Gives the strength of the mightiest warrior", RIng1 = i1, RIng2 = i3, RIng3 = i3 }; r3 = new Recipe { RecipeID = 2, RPotionName = "Potion of Coolness", RPotionDesc = "Makes you really cool", RIng1 = i1, RIng2 = i2, RIng3 = i3 }; frepo.Potions.Clear(); frepo.Recipes.Clear(); frepo.Ingredients.Clear(); frepo.Ingredients.Add(i1); frepo.Ingredients.Add(i2); frepo.Ingredients.Add(i3); pcvm = new PotionCreationViewModel { Ingredients = frepo.Ingredients, Recipes = frepo.Recipes }; prcvm = new PotionRecipeCreationViewModel { Recipes = frepo.Recipes, Ingredients = frepo.Ingredients }; psvm = new PotionStockViewModel { Ingredients = frepo.Ingredients, Potions = frepo.Potions }; rpvm = new RecipePotionViewModel { Recipes = frepo.Recipes }; msvn = new MerchantShopViewModel { IngList = frepo.Ingredients }; }
public IActionResult RecipeBrewing(PotionRecipeCreationViewModel prcvm) { prcvm.Recipes = repo.Recipes; if (ModelState.IsValid) { PotionStockViewModel psvm = new PotionStockViewModel(); prcvm.Ingredients = repo.Ingredients; Recipe rec = repo.getRecipeByID(prcvm.RecipeID); Potion p = repo.getPotionByName(rec.RPotionName); if (p == null) { p = new Potion { PotionName = rec.RPotionName, PotionDescription = rec.RPotionDesc, PIng1 = rec.RIng1, PIng2 = rec.RIng2, PIng3 = rec.RIng3, PotionStock = 1 }; repo.minusIngredientStock(rec); if (rec.RIng1.IngStock < 0 || rec.RIng2.IngStock < 0 || rec.RIng3.IngStock < 0) { repo.addIngredientRecipeStock(rec); prcvm.outOfStock = true; return(View(prcvm)); } repo.addPotion(p); psvm.Potions = repo.Potions; psvm.Ingredients = repo.Ingredients; return(RedirectToAction("PotionStock", psvm)); } repo.minusIngredientStock(rec); if (rec.RIng1.IngStock < 0 || rec.RIng2.IngStock < 0 || rec.RIng3.IngStock < 0) { repo.addIngredientRecipeStock(rec); prcvm.outOfStock = true; return(View(prcvm)); } repo.incrementPotion(p); psvm.Potions = repo.Potions; psvm.Ingredients = repo.Ingredients; return(RedirectToAction("PotionStock", psvm)); } else { return(View(prcvm)); } }