public IActionResult EditGymEquipment(int id) { GymEquipment model = new GymEquipment(); model = gymDAL.GetEquipment(id); return(View(model)); }
public GymEquipment GetEquipment(int id) { GymEquipment equip = new GymEquipment(); try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("Select * From gym_equipment WHERE id = @id ", conn); cmd.Parameters.AddWithValue("@id", id); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { equip = MapRowToEquipment(reader); } return(equip); } } catch (SqlException ex) { throw; } }
public List <GymEquipment> GetEquipments() { List <GymEquipment> list = new List <GymEquipment>(); GymEquipment equip = new GymEquipment(); try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("Select * From gym_equipment ", conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { equip = MapRowToEquipment(reader); list.Add(equip); } return(list); } } catch (SqlException ex) { throw; } }
public bool AddGymEquipment(GymEquipment equip) { try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO gym_equipment (name, usage, photo_path) " + "VALUES (@name, @usage, @photo_path)", conn); cmd.Parameters.AddWithValue("@name", equip.Name); cmd.Parameters.AddWithValue("@usage", equip.ProperUsage); cmd.Parameters.AddWithValue("@photo_path", equip.PhotoPath); cmd.ExecuteNonQuery(); return(true); } } catch (SqlException ex) { return(false); throw; } }
public IActionResult AddGymEquipment(GymEquipment model) { if (ModelState.IsValid) { gymDAL.AddGymEquipment(model); } return(RedirectToAction(nameof(ViewEquipments))); }
public IActionResult AddGymEquipment() { GymEquipment model = new GymEquipment(); return(View(model)); }