refactoring, uppd db in and out
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user