public bool Delete <T>(T entity) where T : class, IEntity { if (IfTrans()) { return(_conn.Delete(entity, _trans)); } using (var connection = GetConnection()) { return(connection.Delete(entity)); } }
public bool Delete(Imovel imovel) { using (MySqlConnection conexao = new MySqlConnection( DBConnection.Configuration.GetConnectionString("imobiliariadb"))) { var imagens = conexao.GetAll <ImagensImovel>().Where(ii => ii.idImovelImagem == imovel.idImovel).ToList(); foreach (var i in imagens) { conexao.Delete(i); } return(conexao.Delete(imovel)); } }
static void Main(string[] args) { //自动 open using (var con = new MySqlConnection("server=localhost;port=3306;uid=root;pwd=admin;database=test")) { var count1 = con.Count <MsgModel2>(); var msgs2 = con.Query <MsgModel2>(m => m.Id == 10); var msg = msgs2.FirstOrDefault(); if (msg != null) { msg.PhoneNum = "sdfsdfdfsdf"; con.Add(msg); msg.PhoneNum = "13344444444"; con.Update(msg); } con.Delete <MsgModel2>(m => m.Id == 10); //事务 成功时返回 true, 失败时 返回 false 会调用回滚 con.Transaction(cmd => { var count = cmd.Delete <MsgModel2>(m => m.Id == 10); if (count == 1) { return(true); } return(false); }); } Console.ReadLine(); }
public IActionResult Delete(int id) { product prod = db.Get <product>(id); db.Delete(prod); return(RedirectToAction("Index")); }
public void DeleteItems(List <Pet> pets) { using (var con = new MySqlConnection(Utils.GetHeWhoMustNotBeNamed())) { con.Delete(pets); } }
public static bool DeleteRptRuntime(RptRuntime rpt) { IDbTransaction tran = null; try { if (rpt == null || string.IsNullOrEmpty(rpt.Id)) { return(false); } using (var conn = new MySqlConnection(CommonConst.ConStr)) { conn.Open(); tran = conn.BeginTransaction(); var flag = conn.Delete(rpt); var result = conn.Execute("delete from rpt_design where Id=@Id", new { Id = rpt.RptId }, tran); flag &= result > 0; tran.Commit(); return(flag); } } catch (Exception ex) { log.Error(string.Format("message:{0},StackTrace:{1}", ex.Message, ex.StackTrace)); if (tran != null) { tran.Rollback(); } return(false); } }
public void Delete(T obj) { using (IDbConnection con = new MySqlConnection(GetConnectionString())) { con.Delete <T>(obj); } }
public IActionResult OnGet(int id, string redirect) { // Authorization AuthorizationResult authorizationResult; if (!Authorization.CheckAuthorization(HttpContext, MySQL, HttpContext.Response, out authorizationResult)) { return(StatusCode(authorizationResult.StatusCode)); } LoginUser = authorizationResult.Account; if (LoginUser.ROLE != "admin") { return(Redirect("/Betakeys")); } if (!String.IsNullOrEmpty(Convert.ToString(id))) { BetaKey DeleteBetakey = MySQL.Get <BetaKey>(id); MySQL.Delete(DeleteBetakey); } if (String.IsNullOrEmpty(redirect)) { return(Redirect("/Betakeys")); } else { return(Redirect(redirect)); } }
public IActionResult Delete(int id) { Product aProd = myDB.Get <Product>(id); myDB.Delete <Product>(aProd); return(RedirectToAction("Index")); }
public IActionResult ConfirmRemove(int id) { Product prod = db.Get <Product>(id); db.Delete(prod); return(RedirectToAction("Index")); }
public IActionResult OnGet(int id, string redirect) { // Authorization AuthorizationResult authorizationResult; if (!Authorization.CheckAuthorization(HttpContext, MySQL, HttpContext.Response, out authorizationResult)) { return(StatusCode(authorizationResult.StatusCode)); } LoginUser = authorizationResult.Account; if (!String.IsNullOrEmpty(Convert.ToString(id))) { ChangeCategory DeleteCategory = MySQL.Get <ChangeCategory>(id); MySQL.Delete(DeleteCategory); } if (String.IsNullOrEmpty(redirect)) { return(Redirect("/Changes/Category/")); } else { return(Redirect(redirect)); } }
public bool DeleteByContrib(UserTag entity) { using (MySqlConnection connection = new MySqlConnection(_conncetionString)) { return(connection.Delete(entity)); } }
public bool Delete(T entity) { using (var connection = new MySqlConnection(_connectionString)) { return(connection.Delete(entity)); } }
public IActionResult Delete(int id) { Product prod = db.Get <Product>(id); db.Delete(prod); return(RedirectToAction("Index", "Home")); //not redirecting to home/index }
public static bool DeleteRptDesign(List <string> rptIds) { IDbTransaction tran = null; try { if (rptIds == null || rptIds.Count == 0) { return(false); } using (var conn = new MySqlConnection(CommonConst.ConStr)) { conn.Open(); tran = conn.BeginTransaction(); var flag = false; foreach (var rpt in rptIds) { flag = conn.Delete(new RptDesign() { Id = rpt }); var result = conn.Execute("delete from rpt_runtime where RptId=@RptId", new { RptId = rpt }, tran); flag &= result > 0; } tran.Commit(); return(flag); } } catch (Exception ex) { log.Error(string.Format("message:{0},StackTrace:{1}", ex.Message, ex.StackTrace)); if (tran != null) { tran.Rollback(); } return(false); } }
public bool delete(dapper.productsub productsub) { using (var connection = new MySqlConnection(conn)) { var identity = connection.Delete <dapper.productsub>(productsub); return(identity); } }
/// <summary> /// Delete /// </summary> /// <param name="model"></param> /// <param name="transaction"></param> /// <param name="commandTimeout"></param> /// <returns>true if deleted, false if not found</returns> public virtual bool Delete(T model, IDbTransaction transaction = null, int?commandTimeout = null) { using (var conn = new MySqlConnection(_connStr)) { conn.Open(); return(conn.Delete(model, transaction, commandTimeout)); } }
internal void DeleteFile(ImagensImovel file) { using (MySqlConnection conexao = new MySqlConnection( DBConnection.Configuration.GetConnectionString("imobiliariadb"))) { conexao.Delete(file); } }
public bool Excluir(Pessoa pessoa) { using (MySqlConnection conexao = new MySqlConnection( _configuracoes.GetConnectionString("BasePost1"))) { return(conexao.Delete <Pessoa>(pessoa)); } }
public ActionResult Delete(int id) { using (var db = new MySqlConnection(ConnectionString)) { var person = Get(id); return(Ok(db.Delete <Person>(person))); } }
public static bool Deletar(Cliente cliente) { using (MySqlConnection connection = new MySqlConnection(con)) { if (cliente != null) { return(connection.Delete(cliente)); } return(false); } }
public static bool DeleteRptDirectory(RptDirectory dir) { IDbTransaction tran = null; try { if (dir == null || string.IsNullOrEmpty(dir.Id)) { return(false); } using (var conn = new MySqlConnection(CommonConst.ConStr)) { conn.Open(); tran = conn.BeginTransaction(); var flag = false; var list = conn.Query <RptDesign> ("select * from rpt_design where DirId=@DirId", new { DirId = dir.Id }, tran).AsList(); if (list == null || list.Count == 0) { flag = conn.Delete(dir, tran); } else { foreach (var rpt in list) { var result = conn.Execute("delete from rpt_runtime where RptId=@RptId", new { RptId = rpt.Id }, tran); flag &= conn.Delete(rpt, tran); flag &= result > 0; } flag &= conn.Delete(dir, tran); } tran.Commit(); return(flag); } } catch (Exception ex) { log.Error(string.Format("message:{0},StackTrace:{1}", ex.Message, ex.StackTrace)); if (tran != null) { tran.Rollback(); } return(false); } }
public void DeleteAccount(int accountId) { using (IDbConnection con = new MySqlConnection(_configuration.GetConnectionString("DefaultConnection"))) { if (con.State == ConnectionState.Closed) { con.Open(); } var account = GetAccountById(accountId); con.Delete <Account>(account); } }
public virtual bool Delete(UInt64 id) { using (var db = new MySqlConnection(ConnectionString)) { var entity = GetById(id); if (entity == null) { throw new Exception("Registro não encontrado"); } return(db.Delete(entity)); } }
public void Delete(int id) { MySqlConnection DBConn = new MySqlConnection("Server = localhost; Database = painatal; Uid = root; Pwd =; "); var res = DBConn.Get <Clientes>(id); if (res != null) { DBConn.Delete(res); } else { } }
public void TestMySqlConnectionDeleteViaTableNameWithoutExpression() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new MySqlConnection(Database.ConnectionString)) { // Act var result = connection.Delete(ClassMappedNameCache.Get <CompleteTable>(), (object)null); // Assert Assert.AreEqual(tables.Count(), result); } }
public int Delete(T entity) { using (var connection = new MySqlConnection(_connectionString)) { try { return(connection.Delete(entity)); } catch { return(0); } } }
public void TestMySqlConnectionDeleteViaTableNameViaPrimaryKey() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new MySqlConnection(Database.ConnectionString)) { // Act var result = connection.Delete <CompleteTable>(tables.First().Id); // Assert Assert.AreEqual(1, result); } }
public void TestMySqlConnectionDeleteViaTableNameViaQueryField() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new MySqlConnection(Database.ConnectionString)) { // Act var result = connection.Delete(ClassMappedNameCache.Get <CompleteTable>(), new QueryField("Id", tables.First().Id)); // Assert Assert.AreEqual(1, result); } }
public void TestMySqlConnectionDeleteViaDynamic() { // Setup var tables = Database.CreateCompleteTables(10); using (var connection = new MySqlConnection(Database.ConnectionString)) { // Act var result = connection.Delete <CompleteTable>(new { Id = tables.First().Id }); // Assert Assert.AreEqual(1, result); } }