public string AddBannedPhone(string bannedPhone) { try { string error = null; using (var connection = _connectionProvider.GetDbConnection()) { connection.Open(); var exists = connection.Execute( @"INSERT INTO banned_phone ( phone ) SELECT @Phone WHERE NOT EXISTS(SELECT 1 FROM banned_phone WHERE phone = @Phone);", new { Phone = bannedPhone }); if (exists == 0) { error = $"Phone '{bannedPhone}' is already in a table"; } } return(error); } catch (Exception e) { return(e.Message); } }
public (IEnumerable <Customer> Customers, string Error) GetAllCustomers() { try { using (var connection = _connectionProvider.GetDbConnection()) { connection.Open(); return( connection.Query <Customer>(@" SELECT id as Id, name as Name, surname as Surname, phone_number as PhoneNumber FROM Customer"), null); } } catch (Exception e) { return(null, e.Message); } }