Guest User

Untitled

a guest
Dec 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. ItemModel {
  2. Id
  3. Name
  4. }
  5.  
  6. Character {
  7. Id
  8. Name
  9. }
  10.  
  11. Loadouts {
  12. Id
  13. CharacterId
  14. Data
  15. }
  16.  
  17. Route[/api/characters/{id}]
  18. GetCharacter(id) -> Character {
  19. Select().Where(id = id)
  20. }
  21.  
  22. Route[/api/characters/{id}/loadouts]
  23. GetCharacterLoadout(id) -> Json<List<Loadouts>> {
  24. CharacterModel model = new CharacterModel();
  25. return Json(model.GetCharacterLoadouts(id));
  26. }
  27.  
  28. // This is inside of a CharacterModel file
  29. Character.GetCharacterLoadouts(id) -> List<Loadouts>{
  30. String command = "SELECT * FROM loadouts WHERE characterId ="+id;
  31. List<Loadouts> loadouts = new List<Loadouts>();
  32.  
  33. NpgsqlCommand cmd = new NpgsqlCommand(command, conn);
  34. NpgsqlDataReader result = cmd.ExecuteReader();
  35.  
  36. while (result.Read())
  37. {
  38. Loadouts loadout = new Loadouts();
  39. loadout.Id = result.GetInt32(0);
  40. loadout.CharacterId = result.GetInt32(1);
  41. loadout.Data = result.GetArray(2);
  42. loadouts.Add(loadout);
  43. }
  44. conn.Close();
  45. return loadouts;
  46. }
Add Comment
Please, Sign In to add comment