Example #1
0
 //render a page that shows all the heroes in the database
 //and allows the user to add a new hero
 public IActionResult ShowHeroes()
 {
     ViewBag.username  = HttpContext.Session.GetString("username");
     ViewBag.allTeams  = MyDbConnector.Query("SELECT * FROM team");
     ViewBag.allHeroes = MyDbConnector.Query("SELECT heroes.*, teams.name as teamname FROM heroes JOIN teams ON heroes.teamId=teams.teamId");
     return(View("Index"));
 }
Example #2
0
        public IActionResult AddHeroToDB(string realName, string superheroName, string villainCheck, string power, int team)
        {
            bool isVillain = true;

            if (villainCheck == null)
            {
                isVillain = false;
            }
            MyDbConnector.Execute($"INSERT INTO heroes (realname, superheroname, isvillain, power) VALUES ('{realName}', '{superheroName}', {isVillain}, '{power}');");
            return(RedirectToAction("/heroes"));
        }