public Utilizador get(int id) { Utilizador res = null; MySqlParameter[] pms = new MySqlParameter[1]; pms[0] = new MySqlParameter("Id", MySqlDbType.Int24); pms[0].Value = id; MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; conn.Open(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "get_user"; cmd.Parameters.AddRange(pms); MySqlDataReader reader = cmd.ExecuteReader(); string nome = "", email = "", morada = ""; while (reader.Read()) { nome = (string)reader["Nome"]; email = (string)reader["Email"]; morada = (string)reader["Morada"]; } res = new Utilizador(id, nome, email, morada); conn.Close(); return(res); }
public void update(Utilizador u) { if (contains(u.getid())) { remove(u.getid()); add(u); } }
//////////////////////////////geral user ////////////////////////////////////// public int add(Utilizador u) { MySqlParameter[] pms = new MySqlParameter[4]; pms[0] = new MySqlParameter("nnome", MySqlDbType.String); pms[0].Value = u.getnome(); pms[1] = new MySqlParameter("nemail", MySqlDbType.String); pms[1].Value = u.getemail(); pms[2] = new MySqlParameter("nmorada", MySqlDbType.String); pms[2].Value = u.getmorada(); pms[3] = new MySqlParameter("npasse", MySqlDbType.String); pms[3].Value = u.getpass(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = conn; conn.Open(); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "inserir_utilizador"; cmd.Parameters.AddRange(pms); cmd.ExecuteNonQuery(); conn.Close(); conn.Open(); cmd = new MySqlCommand("last_id", conn); MySqlDataReader reader = cmd.ExecuteReader(); reader.Read(); int res = reader.GetInt32(0); conn.Close(); return(res); }
public Boolean contains(int i) { Utilizador u = get(i); if (u == null) { return(false); } else { return(true); } }
public static void Main(string[] args) { Utilizador u = users.get(2); /*if (u != null) Console.Write(u.getnome()); * else Console.Write("ola");*/ Receita r = new Receita("ola", "Mousse", null, "123"); int x = receitas.add(r); Console.Write("DDDDDDD " + x); CreateWebHostBuilder(args).Build().Run(); }