Safiron

SQL a XML Mapper

Dec 16th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 KB | None | 0 0
  1. namespace Pineczive.Models.Data_Access
  2. {
  3.     public class LeagueGatewayXML : ILeague
  4.     {
  5.         // VRÁTÍ SEZNAM VŠECH LEAGUE
  6.         public List<League> getLeagues()
  7.         {
  8.             List<League> temp = new List<League>();
  9.             List<string> tempIds = new List<string>();
  10.             List<string> tempNames = new List<string>();
  11.             XDocument doc = XDocument.Load("C:\\Users\\Saphiron\\documents\\visual studio 2012\\Projects\\Pineczive\\Pineczive\\App_Data\\Leagues.xml");
  12.             var ids = doc.Descendants("id");
  13.             var names = doc.Descendants("name");
  14.  
  15.             foreach (var i in ids)
  16.             {
  17.                 tempIds.Add(i.Value.ToString());
  18.             }
  19.  
  20.             foreach (var n in names)
  21.             {
  22.                 tempNames.Add(n.Value.ToString());
  23.             }
  24.  
  25.             for (int i = 0; i < tempIds.Count(); i++)
  26.             {
  27.                 temp.Add(new League(tempIds[i], tempNames[i], false, "cze",string.Empty, string.Empty));
  28.             }
  29.  
  30.             return temp;
  31.         }
  32.     }
  33. }
  34.  
  35. namespace Pineczive.Models.Data_Access
  36. {
  37.     public class LeagueGateway : Connection, ILeague
  38.     {
  39.         private SqlCommand myCommand;
  40.  
  41.         // VRÁTÍ SEZNAM VŠECH LEAGUE
  42.         public List<League> getLeagues()
  43.         {
  44.             string commandText = "SELECT * FROM League";
  45.             List<League> leagueList = new List<League>();
  46.             using (SqlConnection conn = base.NewConnection())
  47.             {
  48.                 conn.Open();
  49.                 myCommand = new SqlCommand(commandText, conn);
  50.                 SqlDataReader myReader = null;
  51.                 myReader = myCommand.ExecuteReader();
  52.                 while (myReader.Read())
  53.                 {
  54.                     leagueList.Add(new League(myReader[0].ToString(), myReader[1].ToString(), Boolean.Parse(myReader[2].ToString()), myReader[3].ToString(), myReader[4].ToString(), myReader[5].ToString()));
  55.                 }
  56.                 myReader.Close();
  57.                 conn.Close();
  58.                 return leagueList;
  59.             }
  60.         }
  61.     }
  62. }
  63.  
  64.  
  65. namespace Pineczive.Models.Business_Logic
  66. {
  67.     interface ILeague
  68.     {
  69.         List<Models.League> getLeagues();
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment