public IActionResult PotionDelete(PotionStockViewModel psvm) { repo.deletePotion(repo.getPotionByID(psvm.PotionID)); psvm.Ingredients = repo.Ingredients; psvm.Potions = repo.Potions; return(View("PotionStock", psvm)); }
public IActionResult PotionStock() { PotionStockViewModel psvm = new PotionStockViewModel(); psvm.Ingredients = repo.Ingredients; psvm.Potions = repo.Potions; return(View(psvm)); }
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)); } }
public IActionResult PotionBrewing(PotionCreationViewModel pcvm) { pcvm.Ingredients = repo.Ingredients; pcvm.Recipes = repo.Recipes; if (ModelState.IsValid) { ViewBag.nameExists = false; Ingredient i1 = repo.getIngredientByID(pcvm.RIng1ID); Ingredient i2 = repo.getIngredientByID(pcvm.RIng2ID); Ingredient i3 = repo.getIngredientByID(pcvm.RIng3ID); Potion p = repo.getPotionByName(pcvm.PotionName); PotionStockViewModel psvm = new PotionStockViewModel(); psvm.Ingredients = repo.Ingredients; psvm.Potions = repo.Potions; if (p != null) { Recipe rec = repo.getRecipeByName(p.PotionName); if (i1 == rec.RIng1 && i2 == rec.RIng2 && i3 == rec.RIng3) { repo.minusIngredientStock(rec); if (i1.IngStock < 0 || i2.IngStock < 0 || i3.IngStock < 0) { repo.addIngredientRecipeStock(rec); pcvm.outOfStock = true; return(View(pcvm)); } else { repo.incrementPotion(p); return(RedirectToAction("PotionStock", psvm)); } } else { pcvm.Error = true; return(View(pcvm)); } } else { Recipe r = repo.getRecipeByName(pcvm.PotionName); if (r == null) { r = new Recipe { RPotionName = pcvm.PotionName, RPotionDesc = pcvm.PotionDesc, RIng1 = i1, RIng2 = i2, RIng3 = i3 }; p = new Potion { PotionName = pcvm.PotionName, PotionDescription = pcvm.PotionDesc, PIng1 = i1, PIng2 = i2, PIng3 = i3, PotionStock = 1 }; repo.minusIngredientStock(r); if (i1.IngStock < 0 || i2.IngStock < 0 || i3.IngStock < 0) { repo.addIngredientRecipeStock(r); pcvm.outOfStock = true; return(View(pcvm)); } repo.addPotion(p); repo.addRecipe(r); return(RedirectToAction("PotionStock", psvm)); } else { if (i1 == r.RIng1 && i2 == r.RIng2 && i3 == r.RIng3) { p = new Potion { PotionName = pcvm.PotionName, PotionDescription = pcvm.PotionDesc, PIng1 = i1, PIng2 = i2, PIng3 = i3, PotionStock = 1 }; repo.minusIngredientStock(r); if (i1.IngStock < 0 || i2.IngStock < 0 || i3.IngStock < 0) { repo.addIngredientRecipeStock(r); pcvm.outOfStock = true; return(View(pcvm)); } repo.addPotion(p); return(RedirectToAction("PotionStock", psvm)); } pcvm.Error = true; return(View(pcvm)); } } } return(View(pcvm)); }