public bool AddData(Area_Model model) { string sql = "insert into Area(name,path,center,title,intro) values (@name,@path,@center,@title,@intro)"; SQLiteCommand cmd = new SQLiteCommand(sql); SQLiteParameter[] sQLiteParameter = { new SQLiteParameter { ParameterName = "@name", DbType = DbType.String, Value = model.name }, new SQLiteParameter { ParameterName = "@path", DbType = DbType.String, Value = model.path.TrimEnd(';') }, new SQLiteParameter { ParameterName = "@center", DbType = DbType.String, Value = model.center.TrimEnd(';') }, new SQLiteParameter { ParameterName = "@title", DbType = DbType.String, Value = model.title.TrimEnd(';') }, new SQLiteParameter { ParameterName = "@intro", DbType = DbType.String, Value = model.intro.TrimEnd(';') } }; int result = SqliteHelper.ExecuteNonQuery(sql, CommandType.Text, sQLiteParameter); if (result > 0) { return(true); } else { return(false); } }
public ActionResult Edit(int id) { string sql = "select id,name,path,center,title,intro from Area where id=@id"; SQLiteParameter[] sQLiteParameter = { new SQLiteParameter { ParameterName = "@id", DbType = DbType.Int32, Value = id }, }; SQLiteCommand cmd = new SQLiteCommand(sql); DataSet result = SqliteHelper.ExecuteDataSet(sql, CommandType.Text, sQLiteParameter); Area_Model area_Model = new Area_Model { id = int.Parse(result.Tables[0].Rows[0]["id"].ToString()), name = result.Tables[0].Rows[0]["name"].ToString(), path = result.Tables[0].Rows[0]["path"].ToString(), center = result.Tables[0].Rows[0]["center"].ToString(), title = result.Tables[0].Rows[0]["title"].ToString(), intro = result.Tables[0].Rows[0]["intro"].ToString(), }; ViewBag.EditModel = JsonConvert.SerializeObject(area_Model); return(View()); }
public Area_Model CreateArea(Area_Model Area_model) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } _context.Area.Add(Area_model); _context.SaveChanges(); return(Area_model); }
public ActionResult editArea(Area_Model ar) { var area = _context.Area.FirstOrDefault(c => c.id == ar.id); if (area == null) { return(HttpNotFound()); } area.nombre = ar.nombre; _context.SaveChanges(); return(View("New", "Area")); }
public void UpdateArea(int id, Area_Model Area) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var AreaDb = _context.Area.SingleOrDefault(c => c.id == id); if (AreaDb == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } AreaDb.nombre = Area.nombre; _context.SaveChanges(); }
public bool EditData(Area_Model model) { string sql = "update Area set name=@name,path=@path,center=@center,title=@title,intro=@intro where id=@id"; SQLiteCommand cmd = new SQLiteCommand(sql); SQLiteParameter[] sQLiteParameter = { new SQLiteParameter { ParameterName = "@name", DbType = DbType.String, Value = model.name }, new SQLiteParameter { ParameterName = "@path", DbType = DbType.String, Value = model.path.TrimEnd(';') }, new SQLiteParameter { ParameterName = "@center", DbType = DbType.String, Value = model.center.TrimEnd(';') }, new SQLiteParameter { ParameterName = "@title", DbType = DbType.String, Value = model.title.TrimEnd(';') }, new SQLiteParameter { ParameterName = "@intro", DbType = DbType.String, Value = model.intro.TrimEnd(';') }, new SQLiteParameter { ParameterName = "@id", DbType = DbType.String, Value = model.id }, }; int result = SqliteHelper.ExecuteNonQuery(sql, CommandType.Text, sQLiteParameter); if (result > 0) { return(true); } else { return(false); } }
public ActionResult createArea(Area_Model area) { _context.Area.Add(area); _context.SaveChanges(); return(RedirectToAction("Index", "Area")); }