Beispiel #1
0
        public IActionResult PotionBrewing()
        {
            // Keep studying the ViewModels
            PotionCreationViewModel pcvm = new PotionCreationViewModel();

            pcvm.Ingredients = repo.Ingredients;
            pcvm.Recipes     = repo.Recipes;
            return(View(pcvm));
        }
Beispiel #2
0
 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
     };
 }
Beispiel #3
0
        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));
        }