Files
BealeEngineering/BealeEngineering/BealeEngineering.Core/Data/Database/Client/CreatePurchaseOrderAllocation.cs
2020-01-31 12:58:09 +00:00

57 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
namespace BealeEngineering.Core.Data.Database.Client
{
public class CreatePurchaseOrderAllocation : Connection
{
public CreatePurchaseOrderAllocation(string sqlConnectionString) : base(sqlConnectionString)
{
}
public int ByDictionary(Dictionary<int, int> saleInvoiceIdToPoLineId)
{
int rowsCreated = 0;
if (saleInvoiceIdToPoLineId == null || !saleInvoiceIdToPoLineId.Any())
{
throw new Exception("No data passed to function.");
}
using (TransactionScope scope = new TransactionScope())
{
using (SqlConnection conn = new SqlConnection(sqlConnectionString))
{
conn.Open();
foreach (var item in saleInvoiceIdToPoLineId)
{
using (SqlCommand cmd = new SqlCommand(@"
INSERT INTO ClientPurchaseOrderLineSalesInvoice (
ClientPurchaseOrderLineID
,SaleInvoiceID
)
VALUES (
@clientPurchaseOrderLineID
,@saleInvoiceID
)
", conn))
{
cmd.Parameters.AddWithValue("@clientPurchaseOrderLineID", item.Value);
cmd.Parameters.AddWithValue("@saleInvoiceID", item.Key);
rowsCreated = rowsCreated + cmd.ExecuteNonQuery();
}
}
}
scope.Complete();
}
return rowsCreated;
}
}
}