Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using WebApplication1.Models;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Web.Http;
- using MySql.Data.MySqlClient;
- namespace WebApplication1.Controllers
- {
- public class UsersController : ApiController
- {
- public IEnumerable<User> GetAllUsers()
- {
- string connStr = "server=sql.edl.pl;user=cenzura;database=mortis_auth;port=3306;password=cenzura;";
- MySqlConnection conn = new MySqlConnection(connStr);
- List<User> users = new List<User>();
- try
- {
- conn.Open();
- string sql = "SELECT id, username, last_ip FROM account";
- MySqlCommand cmd = new MySqlCommand(sql, conn);
- MySqlDataReader reader = cmd.ExecuteReader();
- while (reader.Read())
- {
- User tmpUsr = new Models.User { id = reader.GetInt32("id"), username = reader.GetString("username"), lastip = reader.GetString("last_ip") };
- users.Add(tmpUsr);
- }
- reader.Close();
- } catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- conn.Close();
- return users;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement