using System; using System.Collections.Generic; using System.Transactions; namespace bnhtrade.Core.Logic.Sku { public class SkuService : UnitOfWorkBase { /// /// Used for retriving an SKU ID by parameters. If no match, can create a new SKU if required. /// /// The product Id for the SKU /// The condition Id for the SKU /// The tax code Id for the SKU /// When set to true, if no match is made, function will create a new sku and return the id for that /// Return the id for the new or existing sku or, dependant on set parameters, 0 if not found /// 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; } }); } } }