Exemplo n.º 1
0
        // POST api/<controller>
        public string Post([FromBody] createGame value)
        {
            _conn = new SqlConnection("data source=DESKTOP-M8A87VO;Initial catalog=Gaming; user id= gamingapi; password=frederik0608;");

            var        query         = "insert into Games (game_name,game_publisher,PEGI,game_developer,devices,genre,release_date) values(@game_name,@game_publisher,@PEGI,@game_developer,@devices,@genre,@release_date)";
            SqlCommand insertcommand = new SqlCommand(query, _conn);

            insertcommand.Parameters.AddWithValue("@game_name", value.game_name);
            insertcommand.Parameters.AddWithValue("@game_publisher", value.game_publisher);
            insertcommand.Parameters.AddWithValue("@PEGI", value.PEGI);
            insertcommand.Parameters.AddWithValue("@game_developer", value.game_developer);
            insertcommand.Parameters.AddWithValue("@devices", value.devices);
            insertcommand.Parameters.AddWithValue("@genre", value.genre);
            insertcommand.Parameters.AddWithValue("@release_date", value.release_date);
            _conn.Open();
            //her tager den i modnogle elementer, ude fra og indsætter dem på de plader i databasen, som stemmer over ens med det den har fået af vide de er
            int result = insertcommand.ExecuteNonQuery();

            if (result > 0)
            {
                return("true");
            }
            else
            {
                return("false");
            }
        }
Exemplo n.º 2
0
        // PUT api/<controller>/5
        public string Put(int id, [FromBody] createGame value)
        {
            _conn = new SqlConnection("data source=DESKTOP-M8A87VO;Initial catalog=Gaming; user id= gamingapi; password=frederik0608;");

            var        query         = "update Games set game_name=@game_name,game_publisher=@game_publisher,PEGI=@PEGI,game_developer=@game_developer,genre=@genre,release_date=@release_date where game_id=" + id;
            SqlCommand insertcommand = new SqlCommand(query, _conn);

            insertcommand.Parameters.AddWithValue("@game_name", value.game_name);
            insertcommand.Parameters.AddWithValue("@game_publisher", value.game_publisher);
            insertcommand.Parameters.AddWithValue("@PEGI", value.PEGI);
            insertcommand.Parameters.AddWithValue("@game_developer", value.game_developer);
            insertcommand.Parameters.AddWithValue("@genre", value.genre);
            insertcommand.Parameters.AddWithValue("@release_date", value.release_date);
            //dette er næsten det samme med at den modtager værdiger ude fra usern og der med kan putte det ind på et allrede Extiterne table i databasen
            _conn.Open();
            int result = insertcommand.ExecuteNonQuery();

            if (result > 0)
            {
                return("true");
            }
            else
            {
                return("false");
            }
        }