private string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
public int Execute(string sql)
{
using (SqlConnection con = new SqlConnection("Data Source=DESKTOP-5M0V3KJ;Initial Catalog=ExamDB;Integrated Security=True"))
{
con.Open();
return con.Execute(sql);
}
}
public List<CountryModel> getInfo(string sql)
{
using (SqlConnection con = new SqlConnection("Data Source=DESKTOP-5M0V3KJ;Initial Catalog=ExamDB;Integrated Security=True"))
{
con.Open();
List<CountryModel> list = con.Query<CountryModel>(sql).ToList();
return list;
}
}
DapperHelper helper = new DapperHelper();
[HttpGet]
[Route("api/getInfos")]
public IHttpActionResult getEmail()
{
List<CountryModel> list = helper.getInfo("select * from Country");
return Ok(list);
}
[HttpPost]
[Route("api/AddInfo")]
public int InsertInfo(CountryModel m)
{
int flag = 0;
flag = helper.Execute("insert into Country values ('" + m.Name + "','" + m.Country + "','" + m.Email + "')");
return flag;
}
[HttpPost]
[Route("api/DelInfo")]
public int DeleteInfo(int id)
{
int flag = 0;
flag = helper.Execute("delete from Country where Id=" + id + "");
return flag;
}
[HttpGet]
[Route("api/editSearch")]
public IHttpActionResult Search(int id)
{
List<CountryModel> list = helper.getInfo("select * from Country where Id=" + id + "");
return Ok(list);
}
[HttpPost]
[Route("api/editInfo")]
public int UpdateInfo(CountryModel m,int id)
{
int flag = 0;
flag = helper.Execute("update Country set Name='" + m.Name + "',Country='" + m.Country + "',Email='" + m.Email + "' where Id=" + id + "");
return flag;
}
[HttpGet]
[Route("api/Search")]
public IHttpActionResult SeekInfo(string name)
{
List<CountryModel> list = helper.getInfo("select * from Country where Name like '%" + name + "%'");
return Ok(list);
}