Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. using WebApplication1.Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Http;
  7. using System.Web.Http;
  8. using MySql.Data.MySqlClient;
  9.  
  10. namespace WebApplication1.Controllers
  11. {
  12. public class UsersController : ApiController
  13. {
  14. public IEnumerable<User> GetAllUsers()
  15. {
  16. string connStr = "server=sql.edl.pl;user=cenzura;database=mortis_auth;port=3306;password=cenzura;";
  17. MySqlConnection conn = new MySqlConnection(connStr);
  18. List<User> users = new List<User>();
  19. try
  20. {
  21. conn.Open();
  22. string sql = "SELECT id, username, last_ip FROM account";
  23. MySqlCommand cmd = new MySqlCommand(sql, conn);
  24. MySqlDataReader reader = cmd.ExecuteReader();
  25. while (reader.Read())
  26. {
  27. User tmpUsr = new Models.User { id = reader.GetInt32("id"), username = reader.GetString("username"), lastip = reader.GetString("last_ip") };
  28. users.Add(tmpUsr);
  29. }
  30. reader.Close();
  31. } catch (Exception e)
  32. {
  33. Console.WriteLine(e.ToString());
  34. }
  35. conn.Close();
  36. return users;
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement