public static Groups FindById(int id) { Groups groups = new Groups(); MySqlConnection connection = Behaviors.ConnectionMysql.ReturnConnection(); try { connection.Open(); MySqlCommand cmd = connection.CreateCommand(); cmd.CommandText = "SELECT * FROM groups WHERE id = @id"; cmd.Parameters.AddWithValue("@id", id); MySqlDataReader data = cmd.ExecuteReader(); while (data.Read()) { groups.Id = Convert.ToInt32(data["id"]); groups.Name = data["name"].ToString(); groups.Type = Convert.ToInt32(data["type"]); } } catch (MySqlException e) { throw new ApplicationException(e.Message); } finally { connection.Close(); } return groups; }
public static List<Groups> FindAll() { List<Groups> listGroups = new List<Groups>(); MySqlConnection connection = Behaviors.ConnectionMysql.ReturnConnection(); try { connection.Open(); MySqlCommand cmd = connection.CreateCommand(); cmd.CommandText = "SELECT * FROM groups"; MySqlDataReader data = cmd.ExecuteReader(); while (data.Read()) { Groups groups = new Groups(); groups.Id = Convert.ToInt32(data["id"]); groups.Name = data["name"].ToString(); groups.Type = Convert.ToInt32(data["type"]); listGroups.Add(groups); } } catch (MySqlException e) { throw new ApplicationException(e.Message); } finally { connection.Close(); } return listGroups; }
public void Update(int id, string name, int type) { Groups groups = new Groups { Id = id, Name = name, Type = type }; try { GroupsDal.Update(groups); } catch (ApplicationException e) { throw new ApplicationException(e.Message); } }
public void Save(string name, int type) { Groups groups = new Groups { Name = name, Type = type }; try { GroupsDal.Save(groups); } catch (ApplicationException e) { throw new ApplicationException(e.Message); } }
public Groups FindById(int id) { Groups groups = new Groups(); try { groups = GroupsDal.FindById(id); } catch (ApplicationException e) { throw new ApplicationException(e.Message); } return groups; }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { try { (new GroupsBll()).Update(Convert.ToInt32(Request.Form["id"]), Request.Form["name"], Convert.ToInt32(Request.Form["type"])); Response.Write("Atualizado com sucesso!"); } catch (ApplicationException ex) { Response.Write(ex.Message); } } else { groups = (new GroupsBll()).FindById(Convert.ToInt32(Request.QueryString["id"])); } }
public static void Save(Groups groups) { MySqlConnection connection = Behaviors.ConnectionMysql.ReturnConnection(); try { connection.Open(); MySqlCommand cmd = connection.CreateCommand(); cmd.CommandText = "INSERT INTO groups (name, type) VALUES (@name, @type)"; cmd.Parameters.AddWithValue("@name", groups.Name); cmd.Parameters.AddWithValue("@type", groups.Type); cmd.ExecuteNonQuery(); } catch (MySqlException e) { throw new ApplicationException(e.Message); } finally { connection.Close(); } }
public static void Update(Groups groups) { MySqlConnection connection = Behaviors.ConnectionMysql.ReturnConnection(); try { connection.Open(); MySqlCommand cmd = connection.CreateCommand(); cmd.CommandText = "UPDATE groups SET name = @name, type = @type WHERE id = @id"; cmd.Parameters.AddWithValue("@id", groups.Id); cmd.Parameters.AddWithValue("@name", groups.Name); cmd.Parameters.AddWithValue("@type", groups.Type); cmd.ExecuteNonQuery(); } catch (MySqlException e) { throw new ApplicationException(e.Message); } finally { connection.Close(); } }
protected void Page_Load(object sender, EventArgs e) { groups = new GroupsBll().FindById(Convert.ToInt32(Request.QueryString["id"])); }