mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-05-18 19:48:23 +00:00
wip, this turned into a maaaaaahooosive job
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using bnhtrade.Core.Data.Database.UnitOfWork;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Transactions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace bnhtrade.Core.Logic.Inventory
|
||||
{
|
||||
public class SkuService : UnitOfWorkBase
|
||||
{
|
||||
public SkuService() : base() { }
|
||||
|
||||
internal SkuService(IUnitOfWork unitOfWork) : base(unitOfWork) { }
|
||||
|
||||
/// <summary>
|
||||
/// Used for retriving an SKU ID by parameters. If no match, can create a new SKU if required.
|
||||
/// </summary>
|
||||
/// <param name="productId">The product Id for the SKU</param>
|
||||
/// <param name="conditionId">The condition Id for the SKU</param>
|
||||
/// <param name="accountTaxCodeId">The tax code Id for the SKU</param>
|
||||
/// <param name="noMatchCreateNew">When set to true, if no match is made, function will create a new sku and return the id for that</param>
|
||||
/// <returns>Return the id for the new or existing sku or, dependant on set parameters, 0 if not found</returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public int GetSkuId(int productId, int conditionId, int accountTaxCodeId, bool noMatchCreateNew)
|
||||
{
|
||||
return WithUnitOfWork(uow =>
|
||||
{
|
||||
int? skuId = uow.SkuRepository.ReadSkuId(productId, conditionId, accountTaxCodeId);
|
||||
if (skuId != null)
|
||||
{
|
||||
return (int)skuId;
|
||||
}
|
||||
else if (noMatchCreateNew == false)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int newSkuId = uow.SkuRepository.InsertNewSku(productId, conditionId, accountTaxCodeId);
|
||||
CommitIfOwned(uow);
|
||||
return newSkuId;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user