refactoring, uppd db in and out

This commit is contained in:
2020-12-16 07:28:17 +01:00
parent 79e0fc47f1
commit 2fbc1d8e26
2 changed files with 121 additions and 30 deletions

View File

@ -13,8 +13,9 @@ namespace WindowsFormsCore.Operations
{
public class DBRepo
{
public static void SaveNumberRow(NumberRow numberRow)
public static bool SaveNumberRow(NumberRow numberRow)
{
var output = true;
using(IDbConnection cnn = new SqlConnection(GetConnectionString()))
{
numberRow.NumbersToKey();
@ -54,10 +55,55 @@ namespace WindowsFormsCore.Operations
@Number7
)";
cnn.Execute(sql, p);
try
{
cnn.Execute(sql, p);
}
catch (SqlException ex)
{
if (ex.Number == 2627)
{
output = false;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return output;
}
}
public static NumberRow ReadNumberRow(string numberId)
{
using (IDbConnection cnn = new SqlConnection(GetConnectionString()))
{
var p = new DynamicParameters();
p.Add("@Id", numberId);
string sql = @"select * from dbo.NumbersTable where Id = @Id";
var row = cnn.Query<NumberRow>(sql,p).FirstOrDefault();
row.NumbersToKey();
return row;
}
}
public static IEnumerable<NumberRow> ReadAllNumberRow()
{
using (IDbConnection cnn = new SqlConnection(GetConnectionString()))
{
string sql = @"select * from dbo.NumbersTable ";
var rows = cnn.Query<NumberRow>(sql);
//rows.ToList().ForEach(x => x.KeyToNumbers());
return rows;
}
}
}
}