Exemplo n.º 1
0
        public HomeModule()
        {
            Get["/"] = _ =>
            {
                List <Bills_PC> AllPokemon = Bills_PC.GetAll();
                return(View["index.cshtml", AllPokemon]);
            };

            Post["/pc"] = _ =>
            {
                Bills_PC newEntry = new Bills_PC(Request.Form["dex-no"], Request.Form["name"], Request.Form["nick-name"], Request.Form["lv"]);
                newEntry.Save();
                List <Bills_PC> AllPokemon = Bills_PC.GetAll();
                return(View["index.cshtml", AllPokemon]);
            };

            Post["/DeleteAll"] = _ =>
            {
                Bills_PC.DeleteAll();
                List <Bills_PC> AllPokemon = Bills_PC.GetAll();
                return(View["index.cshtml", AllPokemon]);
            };

            Post["/release"] = _ =>
            {
                foreach (string pokemon in Request.Form["pokemon"])
                {
                    Bills_PC.DeleteOne(pokemon);
                }
                List <Bills_PC> AllPokemon = Bills_PC.GetAll();
                return(View["index.cshtml", AllPokemon]);
            };
        }
Exemplo n.º 2
0
        public static List <Bills_PC> GetAll()
        {
            List <Bills_PC> allBills_PCs = new List <Bills_PC> {
            };

            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand    cmd = new SqlCommand("SELECT * FROM Bills_PC;", conn);
            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                int      dex      = rdr.GetInt32(0);
                string   name     = rdr.GetString(1);
                string   nickName = rdr.GetString(2);
                int      lv       = rdr.GetInt32(3);
                Bills_PC newBill  = new Bills_PC(dex, name, nickName, lv);
                allBills_PCs.Add(newBill);
            }

            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }

            return(allBills_PCs);
        }
Exemplo n.º 3
0
        public void Test_DatabaseEmptyAtFirst()
        {
            //Arrange, Act
            int result     = Bills_PC.GetAll().Count;
            int resultTest = 0;

            //Assert
            Assert.Equal(resultTest, result);
        }
Exemplo n.º 4
0
        public void Test_Save()
        {
            Bills_PC testPokemon = new Bills_PC(001, "Bulbasaur", "Sprite", 11);

            testPokemon.Save();
            List <Bills_PC> result = Bills_PC.GetAll();

            Console.WriteLine(result[0].GetDex() + " " + result[0].GetName() + " " + result[0].GetNick() + " " + result[0].GetLv());
            string resultTest = "Bulbasaur";

            Assert.Equal(resultTest, result[0].GetName());
        }
Exemplo n.º 5
0
 public void Dispose()
 {
     Bills_PC.DeleteAll();
 }