public void Update(int itemId) { // Added Ingredients foreach (ItemGroup itemGroup in _itemGroupsAdded) { itemGroup.SetSourceItemId(itemId); itemGroup.Update(); //ItemIngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, // itemId, itemIngredient.IngredientId, null, // itemIngredient.Amount, itemIngredient.MeasurementUnit); } // Changed Ingredients foreach (ItemGroup itemGroup in _itemGroupsNeedingUpdate) { //ItemIngredient original = ItemIngredient.Get(itemIngredient.Id); //double oldAmount = UnitConversion.Convert(original.Amount, original.MeasurementUnit, // itemIngredient.MeasurementUnit); itemGroup.Update(); //ItemIngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, // itemId, itemIngredient.IngredientId, oldAmount, itemIngredient.Amount, // itemIngredient.MeasurementUnit); } // Removed Ingredients foreach (ItemGroup itemGroup in _itemGroupsRemoved) { //ItemIngredient original = ItemIngredient.Get(itemIngredient.Id); ItemGroup.Delete(itemGroup.Id); //ItemIngredientAdjustment.Add(SessionManager.ActiveEmployee.Id, // itemId, itemIngredient.IngredientId, itemIngredient.Amount, null, // itemIngredient.MeasurementUnit); } _itemGroupsAdded.Clear(); _itemGroupsNeedingUpdate.Clear(); _itemGroupsRemoved.Clear(); }
public void Cancel() { foreach (ItemGroup itemGroup in _itemGroupsAdded) { ItemGroup.Delete(itemGroup.Id); } _itemGroupsAdded.Clear(); _itemGroupsNeedingUpdate.Clear(); _itemGroupsRemoved.Clear(); // Reset UI InitializeListBoxes(); }
public async Task InventoryItemGroup_Delete_DoesDelete() { // Arrange var itemGroup = new ItemGroup { Name = Guid.NewGuid().ToString(), Description = Guid.NewGuid().ToString(), Code = Guid.NewGuid().ToString(), CreatedByUserId = 1, UpdatedByUserId = 1, }; // Act await itemGroup.Create(DbContext); var oldInventoryItemGroupFromDb = DbContext.ItemGroups .AsNoTracking() .First(); await itemGroup.Delete(DbContext); var inventoryItemGroupFromDb = DbContext.ItemGroups .AsNoTracking() .First(); var inventoryItemGroupVersions = DbContext.ItemGroupVersions .AsNoTracking() .ToList(); // Assert Assert.AreEqual(itemGroup.CreatedByUserId, inventoryItemGroupFromDb.CreatedByUserId); Assert.AreEqual(itemGroup.UpdatedByUserId, inventoryItemGroupFromDb.UpdatedByUserId); Assert.AreEqual(itemGroup.Description, inventoryItemGroupFromDb.Description); Assert.AreEqual(itemGroup.Code, inventoryItemGroupFromDb.Code); Assert.AreEqual(itemGroup.Name, inventoryItemGroupFromDb.Name); Assert.AreEqual(2, inventoryItemGroupFromDb.Version); Assert.AreEqual(itemGroup.WorkflowState, inventoryItemGroupFromDb.WorkflowState); Assert.AreEqual(Constants.WorkflowStates.Removed, inventoryItemGroupFromDb.WorkflowState); // versions Assert.AreEqual(2, inventoryItemGroupVersions.Count); Assert.AreEqual(oldInventoryItemGroupFromDb.CreatedByUserId, inventoryItemGroupVersions[0].CreatedByUserId); Assert.AreEqual(oldInventoryItemGroupFromDb.UpdatedByUserId, inventoryItemGroupVersions[0].UpdatedByUserId); Assert.AreEqual(oldInventoryItemGroupFromDb.Description, inventoryItemGroupVersions[0].Description); Assert.AreEqual(oldInventoryItemGroupFromDb.Code, inventoryItemGroupVersions[0].Code); Assert.AreEqual(oldInventoryItemGroupFromDb.Name, inventoryItemGroupVersions[0].Name); Assert.AreEqual(oldInventoryItemGroupFromDb.WorkflowState, inventoryItemGroupVersions[0].WorkflowState); Assert.AreEqual(Constants.WorkflowStates.Created, inventoryItemGroupVersions[0].WorkflowState); Assert.AreEqual(1, inventoryItemGroupVersions[0].Version); Assert.AreEqual(itemGroup.CreatedByUserId, inventoryItemGroupVersions[1].CreatedByUserId); Assert.AreEqual(itemGroup.UpdatedByUserId, inventoryItemGroupVersions[1].UpdatedByUserId); Assert.AreEqual(itemGroup.Name, inventoryItemGroupVersions[1].Name); Assert.AreEqual(itemGroup.Code, inventoryItemGroupVersions[1].Code); Assert.AreEqual(itemGroup.Description, inventoryItemGroupVersions[1].Description); Assert.AreEqual(Constants.WorkflowStates.Removed, inventoryItemGroupVersions[1].WorkflowState); Assert.AreEqual(itemGroup.WorkflowState, inventoryItemGroupVersions[1].WorkflowState); Assert.AreEqual(2, inventoryItemGroupVersions[1].Version); }