public static TTKyThi Save(TTKyThi obj, EntityState state) { if (state == EntityState.Added) { obj.KyThi = _container.Resolve <IKyThiRepository>().Insert(obj); } else { _container.Resolve <IKyThiRepository>().Update(obj); } return(obj); }
public bool Update(TTKyThi obj) { using (IDbConnection db = new SqlConnection(Helper.ConnectionString)) { if (db.State == ConnectionState.Closed) { db.Open(); } int result = db.Execute("sp_KyThi_Update", new { KyThi = obj.KyThi, NgayBatDauDK = obj.NgayBatDauDK, TaiKhoan = obj.TaiKhoan }, commandType: CommandType.StoredProcedure); return(result != 0); } }
public string Insert(TTKyThi obj) { using (IDbConnection db = new SqlConnection(Helper.ConnectionString)) { if (db.State == ConnectionState.Closed) { db.Open(); } DynamicParameters p = new DynamicParameters(); p.AddDynamicParams(new { KyThi = obj.KyThi, NgayBatDauDK = obj.NgayBatDauDK, TaiKhoan = obj.TaiKhoan }); db.Execute("sp_KyThi_Insert", p, commandType: CommandType.StoredProcedure); return(p.Get <string>("@KyThi")); } }
private void btnLuuKiThi_Click(object sender, EventArgs e) { try { bindingSource1.EndEdit(); TTKyThi obj = bindingSource1.Current as TTKyThi; if (obj != null) { obj = KyThiService.Save(obj, objState); //metroGrid1.Refresh(); objState = EntityState.Unchanged; MetroFramework.MetroMessageBox.Show(this, "Đã Cập Nhật Thành Công", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }