using BootCamp.DataAccess; using BootCamp.DataAccess.Contract; using BootCamp.Service.Contract; using System.Threading.Tasks; using BootCamp.Service.Extension; using BootCamp.DataAccess.Common.AWS.DynamoDB.Transaction; using System.Collections.Generic; namespace BootCamp.Service { public class ProductService : IProductService { /// /// The transact scope. /// private TransactScope _scope; /// /// Product provider. /// private readonly IProductProvider _productProvider; public ProductService() { _productProvider = new ProductProvider(); } /// /// Create table service. /// /// /// The table partition key. /// The table sort key. /// public async Task CreateTable(string tableName, string partitionKey, string sortKey) { await _productProvider.CreateTable(tableName, partitionKey, sortKey); } /// /// Read product service. /// /// /// public async Task ReadProduct(ProductModel model) { var dto = await _productProvider.GetProduct(model.ToProductDto()); return dto.ToProductModel(); } /// /// Add product service. /// /// /// public async Task AddProduct(ProductModel model) { await _productProvider.PutProduct(model.ToProductDto(), _scope); } /// /// Delete product service. /// /// /// public async Task DeleteProduct(ProductModel model) { await _productProvider.DeleteProduct(model.ToProductDto(), _scope); } /// /// Begin the transaction mode. /// /// public void BeginTransaction() { if (_scope is null) { _scope = new TransactScope(); } _scope = _scope.Begin(); } /// /// Commit the current transaction. /// /// public async Task CommitTransactionAsync() { await _scope.Commit(); _scope = _scope._parentTransactScope; } /// /// Rollback the current transaction. /// /// public void RollbackTransaction() { _scope.Rollback(); _scope = _scope._parentTransactScope; } } }