public static IEnumerable<Room> FindByBuildingId(int buidingId) { List<Room> rooms = new List<Room>(); MySqlConnection c = getConnection(); MySqlCommand cmd = c.CreateCommand(); c.Open(); cmd.CommandText = "SELECT * FROM rooms where building_id = @buidling_id;"; cmd.Prepare(); cmd.Parameters.AddWithValue("@buidling_id", buidingId); cmd.CommandType = System.Data.CommandType.Text; MySqlDataReader dr = cmd.ExecuteReader(); Room r = null; while (dr.Read()) { r = new Room(); r.Id = dr.GetInt32("id"); r.BuildingId = dr.GetInt32("building_id"); r.Code = dr.GetString("code"); rooms.Add(r); } c.Close(); return rooms; }
public static ICollection<Room> FindByDepartment(int departmentId) { List<Room> rooms = new List<Room>(); MySqlConnection c = getConnection(); MySqlCommand cmd = c.CreateCommand(); cmd.CommandText = "SELECT * FROM rooms where department_id;"; cmd.CommandType = System.Data.CommandType.Text; c.Open(); MySqlDataReader dr = cmd.ExecuteReader(); Room p = null; while (dr.Read()) { p = new Room(); p.Id = dr.GetInt32("id"); p.BuildingId = dr.GetInt32("building_id"); p.Code = dr.GetString("code"); rooms.Add(p); } c.Close(); return rooms; }
public ActionResult Index() { Room r = new Room(); return View(Room.FindAll()); }
public ActionResult Edit(int id, FormCollection collectionn, Room room) { room.Id = id; room.Update(); return RedirectToAction("Index"); }
public ActionResult Delete(int id) { Room p = new Room { Id = id }; p.Delete(); return RedirectToAction("Index"); }
public ActionResult Create(FormCollection collection, Room room) { room.Save(); return RedirectToAction("Index"); }
public static Room FindById(int id) { MySqlConnection c = getConnection(); MySqlCommand cmd = c.CreateCommand(); c.Open(); cmd.CommandText = "SELECT * FROM rooms where id = @id;"; cmd.Prepare(); cmd.Parameters.AddWithValue("@id", id); cmd.CommandType = System.Data.CommandType.Text; MySqlDataReader dr = cmd.ExecuteReader(); Room r = new Room(); while (dr.Read()) { r.Id = dr.GetInt32("id"); r.Code = dr.GetString("code"); r.BuildingId = dr.GetInt32("building_id"); } c.Close(); return r; }