public List <TopicModel> GetListTopic() { List <TopicModel> lstmodel = new List <TopicModel>(); try { con.Open(); SqlCommand cmd = new SqlCommand("Topic_Get_List_Topic", con); cmd.CommandType = CommandType.StoredProcedure; using (con) { using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { TopicModel objStud = new TopicModel(); objStud.ID = Convert.ToInt32(reader["ID"]); objStud.Name_Topic = Convert.ToString(reader["Name_Topic"]); objStud.Description_Topic = Convert.ToString(reader["Description_Topic"]); lstmodel.Add(objStud); } } } con.Close(); return(lstmodel); } catch (Exception objEx) { if (con.State == ConnectionState.Open) { con.Close(); } throw objEx; } }
public int AddNewTopic(TopicModel model) { int res = 0; try { con.Open(); SqlCommand cmd = new SqlCommand("add_new_topic", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@name_topic", model.Name_Topic); cmd.Parameters.AddWithValue("@description_topic", model.Description_Topic); res = cmd.ExecuteNonQuery(); con.Close(); return(res); } catch (Exception objEx) { if (con.State == ConnectionState.Open) { con.Close(); } throw objEx; } }