mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-25 17:17:15 +00:00
Bug fix in ExportSalesInvoice and converted more code over to repository and service pattern
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using bnhtrade.Core.Data.Database.UnitOfWork;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -6,9 +7,17 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Account
|
||||
{
|
||||
public class InvoiceLineItemService
|
||||
public class InvoiceLineItemService : UnitOfWorkBase
|
||||
{
|
||||
private Logic.Log.LogEvent log = new Logic.Log.LogEvent();
|
||||
private Logic.Log.LogEvent _log = new Logic.Log.LogEvent();
|
||||
|
||||
public InvoiceLineItemService()
|
||||
{
|
||||
}
|
||||
|
||||
internal InvoiceLineItemService(IUnitOfWork unitOfWork) : base(unitOfWork)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates new 'default' item code entry. The item code and title are set, will require updating by user before use.
|
||||
@@ -17,25 +26,32 @@ namespace bnhtrade.Core.Logic.Account
|
||||
/// <returns></returns>
|
||||
public Model.Account.InvoiceLineItem CreateNew(string itemCode)
|
||||
{
|
||||
new Data.Database.Account.CreateInvoiceLineItem().CreateDefault(itemCode);
|
||||
var item = new Data.Database.Account.ReadInvoiceLineItem().ByItemCode(new List<string> { itemCode });
|
||||
if (item == null || item.Count == 0)
|
||||
return WithUnitOfWork(uow =>
|
||||
{
|
||||
log.LogError("InvoiceLineItemService.CreateNew", "Error creating new invoice line item in database for item code: " + itemCode);
|
||||
throw new Exception("Error creating new invoice line item in database");
|
||||
}
|
||||
return item[0];
|
||||
uow.InvoiceRepository.CreateDefaultInvoiceLineItem(itemCode);
|
||||
var item = uow.InvoiceRepository.GetInvoiceLineItem(null, new List<string> { itemCode });
|
||||
if (item == null || item.Count == 0)
|
||||
{
|
||||
_log.LogError("InvoiceLineItemService.CreateNew", "Error creating new invoice line item in database for item code: " + itemCode);
|
||||
throw new Exception("Error creating new invoice line item in database");
|
||||
}
|
||||
CommitIfOwned(uow);
|
||||
return item[0];
|
||||
});
|
||||
}
|
||||
|
||||
public Dictionary<string, Model.Account.InvoiceLineItem> GetLineItems(List<string> itemCodes)
|
||||
{
|
||||
var dbResult = new Data.Database.Account.ReadInvoiceLineItem().ByItemCode(itemCodes);
|
||||
var returnDict = new Dictionary<string, Model.Account.InvoiceLineItem>();
|
||||
foreach ( var item in dbResult)
|
||||
return WithUnitOfWork(uow =>
|
||||
{
|
||||
returnDict.Add(item.Value.ItemCode, item.Value);
|
||||
}
|
||||
return returnDict;
|
||||
var dbResult = uow.InvoiceRepository.GetInvoiceLineItem(null, itemCodes);
|
||||
var returnDict = new Dictionary<string, Model.Account.InvoiceLineItem>();
|
||||
foreach (var item in dbResult)
|
||||
{
|
||||
returnDict.Add(item.Value.ItemCode, item.Value);
|
||||
}
|
||||
return returnDict;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user