public async Task <JsonResult> Create(TDemoTable model) { model.F_Guid = Guid.NewGuid().ToString(); using (var db = new MysqlDb()) { db.TDemoTable.Add(model); await db.SaveChangesAsync(); return(Json(new { state = true, value = "操作成功" })); } }
/// <summary> /// 删除 /// </summary> /// <returns></returns> public async Task <JsonResult> Remove(int id) { using (var db = new MysqlDb()) { await db.TDemoTable.RemoveById(id); await db.SaveChangesAsync(); return(Json(new { state = true, value = "删除成功" })); } }
/// <summary> /// 保存数据库 /// </summary> /// <param name="model"></param> /// <returns></returns> private async Task Add(TDemoTable model) { using (var db = new MysqlDb()) { db.TDemoTable.Add(model); await db.SaveChangesAsync(); MessageBox.Show(JsonSerializer.Serialize(model)); await InitializeData(); } }
public async Task <JsonResult> Edit(TDemoTable model) { if (!this.TryValidateModel(model)) { return(Json(new { state = false, value = this.ModelState.FirstModelErrorMessage() })); } using (var db = new MysqlDb()) { db.Entry(model).State = EntityState.Modified; await db.SaveChangesAsync(); return(Json(new { state = true, value = "编辑成功" })); } }
/// <summary> /// 菜单删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void DeleteToolStripMenuItem_Click(object sender, EventArgs e) { int a = dataGridView1.CurrentRow.Index; var f_id = dataGridView1.Rows[a].Cells["Id"].Value; var id = int.Parse(f_id.ToString()); using (var db = new MysqlDb()) { await db.TDemoTable.RemoveById(id); await db.SaveChangesAsync(); } MessageBox.Show("删除id:" + id + "成功."); await InitializeData(); }