mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-05-18 19:48:23 +00:00
41 lines
1.6 KiB
C#
41 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Transactions;
|
|
|
|
namespace bnhtrade.Core.Logic.Sku
|
|
{
|
|
public class SkuService : UnitOfWorkBase
|
|
{
|
|
/// <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;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|