public void AddProductInventorySnapshotToDb(EntityInventories.ProductInventory productInventoryRecord) { var snapshotToAdd = new EntityInventories.ProductInventorySnapshot() { Product = productInventoryRecord.Product, QuantityAvailable = productInventoryRecord.QuantityAvailable, SnapshotTime = DateTime.Now }; _dbContext.Add(snapshotToAdd); _dbContext.SaveChanges(); }
public void CreateProductInventoryRecord(ServiceProducts.Product product) { // there's no valid id we can use to retrieve by id, because it gets generated automatcially by DB when that product is added var entityProduct = _productsReader.GetMostRecentlyAddedProductFromDb(); var now = DateTime.Now; try { var productInventoryRecord = new EntityInventories.ProductInventory() { Product = entityProduct.Name == product.Name ? entityProduct : null, QuantityAvailable = 0, IdealQuantity = 15, CreatedOn = now, UpdatedOn = now }; _inventoriesWriter.AddProductInventoryRecordToDb(productInventoryRecord); } catch (Exception) { throw new InvalidOperationException($"Failed to add inventory record for product {product.Name}. Most recently added entity product retreived was {entityProduct.Name}"); } }
public void AddProductInventoryRecordToDb(EntityInventories.ProductInventory productInventoryRecord) { _dbContext.Add(productInventoryRecord); _dbContext.SaveChanges(); }