Exemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            WeaponStatViewModel model = new WeaponStatViewModel();


            List <Stat> statResult = (from s in _context.Stats select s).ToList();

            // Get stats from DB
            model.WeaponStats = statResult; // all weapon stats
            model.AllWeapons  = await WeaponDb.GetAllWeapons(_context);

            ViewData["userMsg"] = "Apply button applies both weapons and all selected stats.";

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(WeaponStatViewModel model, IFormCollection form)
        {
            List <Stat> statResult = (from s in _context.Stats select s).ToList();

            // Get stats from DB
            model.WeaponStats = statResult; // all weapon stats
            model.AllWeapons  = await WeaponDb.GetAllWeapons(_context);

            // Gets both weapons from Index View
            string firstWeap  = Request.Form["firstWeapon"];
            string secondWeap = Request.Form["secondWeapon"];

            // Gets all selected stats from Index View
            model.SelectedStats = await getSelectedStats(form);

            // Checks if weapons are selected
            if (firstWeap != null && firstWeap != "" && secondWeap != null && secondWeap != "" && firstWeap != secondWeap)
            {
                // Adds selected weapons to ViewModel
                int firstWeapSelected = int.Parse(firstWeap);
                model.ChosenWeapon1 = await WeaponDb.GetWeaponById(firstWeapSelected, _context);

                int secondWeapSelected = int.Parse(secondWeap);
                model.ChosenWeapon2 = await WeaponDb.GetWeaponById(secondWeapSelected, _context);

                // If stats are selected add them to weapon stats
                if (model.SelectedStats.Count() != 0)
                {
                    model.ChosenWeapon1 = addSelectedStats(model.SelectedStats, model.ChosenWeapon1);
                    model.ChosenWeapon2 = addSelectedStats(model.SelectedStats, model.ChosenWeapon2);
                }

                // ViewData["userMsg"] = model.ChosenWeapon1.WeaponName + " and " + model.ChosenWeapon2.WeaponName;
            }
            else
            {
                ViewData["userMsg"] = "Please select two different weapons before applying";
            }

            return(View(model));
        }