public void Update(Sms_logs prod) { using (IDbConnection dbConnection = _provider.GetDbConnection()) { string sQuery = "UPDATE sms_logs SET (mobile, code, end_time,create_time)" + " VALUES(@mobile, @code, @end_time, @create_time) WHERE id = @Id"; dbConnection.Open(); dbConnection.Query(sQuery, prod); } }
public void Add(Sms_logs admin) { using (IDbConnection dbConnection = _provider.GetDbConnection()) { string sQuery = "INSERT INTO sms_logs (mobile, code, end_time,create_time,update_time)" + " VALUES(@mobile, @code, @end_time, @create_time,@update_time)"; dbConnection.Open(); dbConnection.Execute(sQuery, admin); } }
public async Task UpdateAsync(Sms_logs invoice) { using (var connection = _provider.GetDbConnection()) using (var transaction = connection.BeginTransaction()) { try { var query = "UPDATE sms_logs SET (mobile, code, end_time,create_time)" + " VALUES(@mobile, @code, @end_time, @create_time) WHERE id = @Id"; await connection.ExecuteAsync(query, invoice, transaction); var lineIds = new List <int>(); //lineIds.AddRange(invoice.Where(l => l.Id != 0).Select(l => l.Id)); //foreach (var line in invoice.InvoiceLines) //{ // if (line.Id == 0) // { // query = "INSERT INTO InvoiceLines (LineItem, Amount, Unit, UnitPrice, VatPercent, InvoiceId)"; // query += "VALUES (@LineItem, @Amount, @Unit, @UnitPrice, @VatPercent," + invoice.Id + "); "; // query += "SELECT CAST(SCOPE_IDENTITY() AS INT)"; // var id = await connection.QueryFirstAsync<int>(query, line, transaction); // lineIds.Add(id); // } // else // { // query = "UPDATE InvoiceLines SET LineItem=@LineItem,Amount=@Amount,Unit=@Unit,"; // query += "UnitPrice=@UnitPrice,VatPercent=@VatPercent "; // query += "WHERE Id=@Id"; // await connection.ExecuteAsync(query, line, transaction); // } //} //if (lineIds.Count > 0) //{ // query = "DELETE FROM InvoiceLines WHERE InvoiceId=" + invoice.Id + " AND "; // query += "Id NOT IN(" + string.Join(',', lineIds) + ")"; // await connection.ExecuteAsync(query, transaction: transaction); //} transaction.Commit(); } catch { transaction.Rollback(); throw; } } }