public ServiceInventories.ProductInventory GetProductInventoryRecordByProductId(int id) { var entityProductInventory = _inventoriesReader.GetProductInventoryRecordFromDbByProductId(id); var serviceProductInventory = InventoryMapper.SerialiseProductInventoryRecord(entityProductInventory); return(serviceProductInventory); }
public IEnumerable <ServiceInventories.ProductInventory> GetCurrentProductInventory() { var entityProductInventories = _inventoriesReader.GetCurrentProductInventoryFromDb(); var serviceProductInventories = entityProductInventories .Select(pi => InventoryMapper .SerialiseProductInventoryRecord(pi)); return(serviceProductInventories); }
// not a fan of the nested try/catch. Must be a better way public ServiceResponse <ServiceInventories.ProductInventory> UpdateQuantityAvailable(int productId, int adjustment) { var productInventory = _inventoriesReader.GetProductInventoryRecordFromDbByProductId(productId); var now = DateTime.Now; var response = new ServiceResponse <ServiceInventories.ProductInventory>() { Time = now }; try { _inventoriesWriter.UpdateQuantityAvailableInDb(productId, adjustment); try { productInventory.UpdatedOn = now; _inventoriesWriter.AddProductInventorySnapshotToDb(productInventory); } catch (Exception e) { _logger.LogError($"Failed to create product inventory snapshot for product inventory record {productInventory.Id} pertaining to product {productId}. " + $"Stack trace: {e.StackTrace}"); } response.IsSuccessful = true; response.Data = InventoryMapper.SerialiseProductInventoryRecord(productInventory); response.Message = $"Quantity successfully updated to {productInventory.QuantityAvailable} for product inventory record {productInventory.Id} pertaining to product {productId}"; } catch (Exception e) { response.IsSuccessful = false; response.Data = InventoryMapper.SerialiseProductInventoryRecord(productInventory); response.Message = $"Failed to update quanitity for product inventory record {productInventory.Id} pertaining to product {productId}. Stack trace: {e.StackTrace}"; } return(response); }