public IEnumerable <Venting> list() { List <Venting> lst = new List <Venting>(); string con = "datasource=localhost;port=3306;username=root;password=1234qwer"; string query = $"select * from login.secrets order by id"; using (MySqlConnection myconn = new MySqlConnection(con)) { MySqlCommand mycomm = new MySqlCommand(query, myconn); myconn.Open(); MySqlDataReader reader = mycomm.ExecuteReader(); while (reader.Read()) { Venting div = new Venting(); div.id = Convert.ToInt32(reader["id"]); div.title = reader["title"].ToString(); div.secret = reader["secret"].ToString(); lst.Add(div); } myconn.Close(); } return(lst); }
public IActionResult write(Venting vent) { TempData["Success"] = "Locked away :) !"; datas da = new datas(); da.story(vent); return(View("write")); }
public IActionResult writing(int id, [Bind] Venting venting) { datas da = new datas(); if (id != venting.id) { return(NotFound()); } if (ModelState.IsValid) { da.updateDiary(venting); return(RedirectToAction("lists")); } return(View(venting)); }
public IActionResult writing(int?id) { datas da = new datas(); if (id == null) { return(NotFound()); } Venting ben = da.GetDiary(id); if (ben == null) { return(NotFound()); } return(View(ben)); }
public IActionResult Delete(int?id) { datas da = new datas(); if (id == null) { return(NotFound()); } Venting va = da.GetDiary(id); if (da == null) { return(NotFound()); } return(View(va)); }
public void story(Venting vent) { try { string con = "datasource=localhost;port=3306;username=root;password=1234qwer"; string query = $"insert into login.secrets(title,secret)values('{vent.title}','{vent.secret}');"; MySqlConnection myconn = new MySqlConnection(con); MySqlCommand mycomm = new MySqlCommand(query, myconn); MySqlDataReader reader; myconn.Open(); reader = mycomm.ExecuteReader(); while (reader.Read()) { } myconn.Close(); } catch (Exception exo) { Console.Write("no connection with database"); } }
public void updateDiary(Venting venting) { string con = "datasource=localhost;port=3306;username=root;password=1234qwer"; using (MySqlConnection myconn = new MySqlConnection(con)) { string query = $"update login.secrets set secret=@secret where id = @id"; MySqlCommand mycomm = new MySqlCommand(query, myconn); mycomm.Parameters.AddWithValue("@id", venting.id); mycomm.Parameters.AddWithValue("@secret", venting.secret); myconn.Open(); mycomm.ExecuteNonQuery(); myconn.Close(); } }
public Venting GetDiary(int?id) { Venting div = new Venting(); string con = "datasource=localhost;port=3306;username=root;password=1234qwer"; using (MySqlConnection myconn = new MySqlConnection(con)) { string query = $"select * from login.secrets where id =" + id; MySqlCommand mycomm = new MySqlCommand(query, myconn); myconn.Open(); MySqlDataReader reader = mycomm.ExecuteReader(); while (reader.Read()) { div.id = Convert.ToInt32(reader["id"]); div.title = reader["title"].ToString(); div.secret = reader["secret"].ToString(); } } return(div); }
public IActionResult setup() { string delete = Request.Query["delete"]; string type = Request.Query["type"]; string sindex = Request.Query["index"]; if (!String.IsNullOrEmpty(delete)) { //string uid = Request.Query["uid"]; MQTTProcess item = items[int.Parse(Request.Query["switch"]) - 1]; for (int i = triggers[item].Count - 1; i >= 0; i--) { Trigger t = triggers[item][i]; if (t.uid == delete) { triggers[item].RemoveAt(i); return(new JsonResult(new { status = "OK", systime = DateTime.Now.ToString("HH:mm:ss") })); } } } else if (type == "switch") { List <Trigger> list = new List <Trigger>(); MQTTProcess item = items[int.Parse(sindex) - 1]; return(Json(new { items = triggers[item].ToArray() })); } else if (type == "onoff") { MQTTProcess item = items[int.Parse(Request.Query["switch"]) - 1]; string uid = Request.Query["uid"]; if (uid == "0") { OnOffTrigger tr = new OnOffTrigger(); tr.time = Request.Query["time"]; tr.days = Request.Query["days"]; tr.name = Request.Query["name"]; if (Request.Query["action"] == "true") { tr.action = "on"; } else { tr.action = "off"; } triggers[item].Add(tr); return(new JsonResult(new { status = "OK", systime = DateTime.Now.ToString("HH:mm:ss") })); } else { foreach (Trigger t in triggers[item]) { if (t.uid == uid) { if (t.type == "onoff") { OnOffTrigger tr = t as OnOffTrigger; tr.time = Request.Query["time"]; tr.days = Request.Query["days"]; tr.name = Request.Query["name"]; if (Request.Query["action"] == "true") { tr.action = "on"; } else { tr.action = "off"; } return(new JsonResult(new { status = "OK", systime = DateTime.Now.ToString("HH:mm:ss") })); } } } } } else if (type == "pwm") { MQTTProcess item = items[int.Parse(Request.Query["switch"]) - 1]; string uid = Request.Query["uid"]; if (uid == "0") { PWMTrigger tr = new PWMTrigger(); tr.onlength = Request.Query["onlength"]; tr.offlength = Request.Query["offlength"]; tr.days = Request.Query["days"]; tr.name = Request.Query["name"]; triggers[item].Add(tr); return(new JsonResult(new { status = "OK", systime = DateTime.Now.ToString("HH:mm:ss") })); } else { foreach (Trigger t in triggers[item]) { if (t.uid == uid) { if (t.type == "pwm") { PWMTrigger tr = t as PWMTrigger; tr.onlength = Request.Query["onlength"]; tr.offlength = Request.Query["offlength"]; tr.days = Request.Query["days"]; tr.name = Request.Query["name"]; return(new JsonResult(new { status = "OK", systime = DateTime.Now.ToString("HH:mm:ss") })); } } } } } else if (type == "termo") { MQTTProcess item = items[int.Parse(Request.Query["switch"]) - 1]; string uid = Request.Query["uid"]; if (uid == "0") { Termostat tr = new Termostat(); tr.start = Request.Query["start"]; tr.end = Request.Query["end"]; tr.min = Request.Query["min"]; tr.max = Request.Query["max"]; tr.variable = Request.Query["variable"]; tr.days = Request.Query["days"]; tr.name = Request.Query["name"]; triggers[item].Add(tr); return(new JsonResult(new { status = "OK", systime = DateTime.Now.ToString("HH:mm:ss") })); } else { foreach (Trigger t in triggers[item]) { if (t.uid == uid) { if (t.type == "termo") { Termostat tr = t as Termostat; tr.start = Request.Query["start"]; tr.end = Request.Query["end"]; tr.min = Request.Query["min"]; tr.max = Request.Query["max"]; tr.variable = Request.Query["variable"]; tr.days = Request.Query["days"]; tr.name = Request.Query["name"]; return(new JsonResult(new { status = "OK", systime = DateTime.Now.ToString("HH:mm:ss") })); } } } } } else if (type == "vent") { MQTTProcess item = items[int.Parse(Request.Query["switch"]) - 1]; string uid = Request.Query["uid"]; if (uid == "0") { Venting tr = new Venting(); tr.start = Request.Query["start"]; tr.end = Request.Query["end"]; tr.min = Request.Query["min"]; tr.max = Request.Query["max"]; tr.variable = Request.Query["variable"]; tr.days = Request.Query["days"]; tr.name = Request.Query["name"]; triggers[item].Add(tr); return(new JsonResult(new { status = "OK", systime = DateTime.Now.ToString("HH:mm:ss") })); } else { foreach (Trigger t in triggers[item]) { if (t.uid == uid) { if (t.type == "vent") { Venting tr = t as Venting; tr.start = Request.Query["start"]; tr.end = Request.Query["end"]; tr.min = Request.Query["min"]; tr.max = Request.Query["max"]; tr.variable = Request.Query["variable"]; tr.days = Request.Query["days"]; tr.name = Request.Query["name"]; return(new JsonResult(new { status = "OK", systime = DateTime.Now.ToString("HH:mm:ss") })); } } } } } else if (type == "timeout") { MQTTProcess item = items[int.Parse(Request.Query["switch"]) - 1]; string uid = Request.Query["uid"]; if (uid == "0") { Timeout tr = new Timeout(); tr.len = Request.Query["len"]; if (Request.Query["action"] == "true") { tr.action = "on"; } else { tr.action = "off"; } tr.days = Request.Query["days"]; tr.name = Request.Query["name"]; triggers[item].Add(tr); return(new JsonResult(new { status = "OK", systime = DateTime.Now.ToString("HH:mm:ss") })); } else { foreach (Trigger t in triggers[item]) { if (t.uid == uid) { if (t.type == "timeout") { Timeout tr = t as Timeout; tr.len = Request.Query["len"]; if (Request.Query["action"] == "true") { tr.action = "on"; } else { tr.action = "off"; } tr.days = Request.Query["days"]; tr.name = Request.Query["name"]; return(new JsonResult(new { status = "OK", systime = DateTime.Now.ToString("HH:mm:ss") })); } } } } } return(NotFound()); }