public ActionResult Show(string db, string tb) { Table table = new Table(); Row row = new Row(); table.name = tb; table.collection = row.GetAll(db,tb); ViewData["collection"] = table; ViewBag.database = db; return View(); }
/// <summary> /// Get all rows like collection in Table /// </summary> /// <param name="db"></param> /// <param name="table"></param> /// <returns>ICollection<Row></returns> public ICollection<Row> GetAll(string db, string table) { Element element; Row row; ICollection<Row> collection= new List<Row>(); IDictionary<object, string> d = null; this.GetColumn(db,table); Connection c = new MysqlConecction(); IDbConnection cnn = c.Change(db); String query = @"Select * from " +table+" LIMIT 5;"; try { var registro = SqlMapper.Query<object>(cnn, query, null, commandType: CommandType.Text); IDictionary<string, object> diccionary; foreach (var item in registro) { diccionary = (IDictionary<string, object>)item; row = new Row(); row.content = new List<Element>(); // Two collection in one foreach //collection 1. diccionary.Keys (nw.item1) //collection 2. diccionary.values (nw.item2) foreach (var nw in diccionary.Keys.Zip(diccionary.Values, Tuple.Create)) { element = new Element(); if (nw.Item1.Equals(column.Peek().name)) { element.name = nw.Item1; element.value = nw.Item2.ToString(); element.type = column.Peek().type; element.isKey = column.Dequeue().isKey; row.content.Add(element); } } column = new Queue<Element>(columnBack); collection.Add(row); } } catch (Exception e) { } finally { c.Close(cnn); } return collection; }
public ActionResult Save() { Row column = (Row)Session["data"]; Row element = new Row(); element.content = new List<Element>(); foreach (Element item in column.content) { item.value = Request[item.name]; element.content.Add(item); } Session.Remove("Row"); string db = Session["db"].ToString(); string tb = Session["tb"].ToString(); Session.Remove("db"); Session.Remove("tb"); element.Update(db, tb); return RedirectToAction("Show", new { db = db, tb = tb }); }
public ActionResult Delete(string db, string tb, string key, string value) { Row row = new Row(); row.Delete(db, tb, key,value); return RedirectToAction("Show", new { db= db, tb = tb}); }