private void Delete() { ItemType itemType = ItemType.GetByKey(wneTypeId.ValueInt); if (itemType != null) { if (itemType.Delete(HyperCatalog.Shared.SessionState.User.Id)) { lbError.Visible = false; lbError.Text = string.Empty; panelEdit.Visible = false; panelGrid.Visible = true; UpdateDataView(); } else { lbError.CssClass = "hc_error"; lbError.Text = "Error: this item type is still used"; lbError.Visible = true; } } else { lbError.CssClass = "hc_error"; lbError.Text = "Error: a system error occurred"; lbError.Visible = true; } }
public void DeleteItem(ItemType itemType) { if (itemType != null && !itemType.IsDefault && ItemTypes.Count != 1) { itemType.Delete(); ItemTypes.Remove(itemType); } }
public async Task InventoryItemType_Delete_DoesDelete() { // Arrange var itemType = new ItemType { Name = Guid.NewGuid().ToString(), BaseUnitOfMeasure = Guid.NewGuid().ToString(), Comment = Guid.NewGuid().ToString(), CostingMethod = CostingMethod.Lifo, Description = Guid.NewGuid().ToString(), EformId = 1, CreatedByUserId = 1, GrossWeight = 1, GtinEanUpc = Guid.NewGuid().ToString(), LastPhysicalInventoryDate = new DateTime(2050, 1, 1, 1, 1, 1), NetWeight = 1, No = Guid.NewGuid().ToString(), ProfitPercent = 1, Region = 1, RiskDescription = Guid.NewGuid().ToString(), SalesUnitOfMeasure = UnitOfMeasure.Liter, StandardCost = 1, Usage = Guid.NewGuid().ToString(), UpdatedByUserId = 1, UnitVolume = 1, UnitPrice = 1, UnitCost = 1, }; // Act await itemType.Create(DbContext); var oldInventoryItemTypeFromDb = DbContext.ItemTypes .AsNoTracking() .First(); await itemType.Delete(DbContext); var inventoryItemTypeFromDb = DbContext.ItemTypes .AsNoTracking() .ToList(); var inventoryItemTypeVersions = DbContext.ItemTypeVersions .AsNoTracking() .ToList(); // Assert Assert.AreEqual(1, inventoryItemTypeFromDb.Count); Assert.AreEqual(itemType.CreatedByUserId, inventoryItemTypeFromDb[0].CreatedByUserId); Assert.AreEqual(itemType.UpdatedByUserId, inventoryItemTypeFromDb[0].UpdatedByUserId); Assert.AreEqual(itemType.Name, inventoryItemTypeFromDb[0].Name); Assert.AreEqual(itemType.BaseUnitOfMeasure, inventoryItemTypeFromDb[0].BaseUnitOfMeasure); Assert.AreEqual(itemType.Comment, inventoryItemTypeFromDb[0].Comment); Assert.AreEqual(itemType.CostingMethod, inventoryItemTypeFromDb[0].CostingMethod); Assert.AreEqual(itemType.Description, inventoryItemTypeFromDb[0].Description); Assert.AreEqual(itemType.EformId, inventoryItemTypeFromDb[0].EformId); Assert.AreEqual(itemType.GrossWeight, inventoryItemTypeFromDb[0].GrossWeight); Assert.AreEqual(itemType.GtinEanUpc, inventoryItemTypeFromDb[0].GtinEanUpc); Assert.AreEqual(itemType.LastPhysicalInventoryDate, inventoryItemTypeFromDb[0].LastPhysicalInventoryDate); Assert.AreEqual(itemType.NetWeight, inventoryItemTypeFromDb[0].NetWeight); Assert.AreEqual(itemType.No, inventoryItemTypeFromDb[0].No); Assert.AreEqual(itemType.ProfitPercent, inventoryItemTypeFromDb[0].ProfitPercent); Assert.AreEqual(itemType.Region, inventoryItemTypeFromDb[0].Region); Assert.AreEqual(itemType.RiskDescription, inventoryItemTypeFromDb[0].RiskDescription); Assert.AreEqual(itemType.SalesUnitOfMeasure, inventoryItemTypeFromDb[0].SalesUnitOfMeasure); Assert.AreEqual(itemType.StandardCost, inventoryItemTypeFromDb[0].StandardCost); Assert.AreEqual(itemType.Usage, inventoryItemTypeFromDb[0].Usage); Assert.AreEqual(itemType.UnitVolume, inventoryItemTypeFromDb[0].UnitVolume); Assert.AreEqual(itemType.UnitPrice, inventoryItemTypeFromDb[0].UnitPrice); Assert.AreEqual(itemType.UnitCost, inventoryItemTypeFromDb[0].UnitCost); Assert.AreEqual(2, inventoryItemTypeFromDb[0].Version); Assert.AreEqual(Constants.WorkflowStates.Removed, inventoryItemTypeFromDb[0].WorkflowState); Assert.AreEqual(itemType.WorkflowState, inventoryItemTypeFromDb[0].WorkflowState); // versions Assert.AreEqual(2, inventoryItemTypeVersions.Count); Assert.AreEqual(oldInventoryItemTypeFromDb.CreatedByUserId, inventoryItemTypeVersions[0].CreatedByUserId); Assert.AreEqual(oldInventoryItemTypeFromDb.UpdatedByUserId, inventoryItemTypeVersions[0].UpdatedByUserId); Assert.AreEqual(oldInventoryItemTypeFromDb.Name, inventoryItemTypeVersions[0].Name); Assert.AreEqual(oldInventoryItemTypeFromDb.BaseUnitOfMeasure, inventoryItemTypeVersions[0].BaseUnitOfMeasure); Assert.AreEqual(oldInventoryItemTypeFromDb.Comment, inventoryItemTypeVersions[0].Comment); Assert.AreEqual(oldInventoryItemTypeFromDb.CostingMethod, inventoryItemTypeVersions[0].CostingMethod); Assert.AreEqual(oldInventoryItemTypeFromDb.Description, inventoryItemTypeVersions[0].Description); Assert.AreEqual(oldInventoryItemTypeFromDb.EformId, inventoryItemTypeVersions[0].EformId); Assert.AreEqual(oldInventoryItemTypeFromDb.GrossWeight, inventoryItemTypeVersions[0].GrossWeight); Assert.AreEqual(oldInventoryItemTypeFromDb.GtinEanUpc, inventoryItemTypeVersions[0].GtinEanUpc); Assert.AreEqual(oldInventoryItemTypeFromDb.LastPhysicalInventoryDate, inventoryItemTypeVersions[0].LastPhysicalInventoryDate); Assert.AreEqual(oldInventoryItemTypeFromDb.NetWeight, inventoryItemTypeVersions[0].NetWeight); Assert.AreEqual(oldInventoryItemTypeFromDb.No, inventoryItemTypeVersions[0].No); Assert.AreEqual(oldInventoryItemTypeFromDb.ProfitPercent, inventoryItemTypeVersions[0].ProfitPercent); Assert.AreEqual(oldInventoryItemTypeFromDb.Region, inventoryItemTypeVersions[0].Region); Assert.AreEqual(oldInventoryItemTypeFromDb.RiskDescription, inventoryItemTypeVersions[0].RiskDescription); Assert.AreEqual(oldInventoryItemTypeFromDb.SalesUnitOfMeasure, inventoryItemTypeVersions[0].SalesUnitOfMeasure); Assert.AreEqual(oldInventoryItemTypeFromDb.StandardCost, inventoryItemTypeVersions[0].StandardCost); Assert.AreEqual(oldInventoryItemTypeFromDb.Usage, inventoryItemTypeVersions[0].Usage); Assert.AreEqual(oldInventoryItemTypeFromDb.UnitVolume, inventoryItemTypeVersions[0].UnitVolume); Assert.AreEqual(oldInventoryItemTypeFromDb.UnitPrice, inventoryItemTypeVersions[0].UnitPrice); Assert.AreEqual(oldInventoryItemTypeFromDb.UnitCost, inventoryItemTypeVersions[0].UnitCost); Assert.AreEqual(oldInventoryItemTypeFromDb.Id, inventoryItemTypeVersions[0].ItemTypeId); Assert.AreEqual(Constants.WorkflowStates.Created, inventoryItemTypeVersions[0].WorkflowState); Assert.AreEqual(oldInventoryItemTypeFromDb.WorkflowState, inventoryItemTypeVersions[0].WorkflowState); Assert.AreEqual(1, inventoryItemTypeVersions[0].Version); Assert.AreEqual(itemType.CreatedByUserId, inventoryItemTypeVersions[1].CreatedByUserId); Assert.AreEqual(itemType.UpdatedByUserId, inventoryItemTypeVersions[1].UpdatedByUserId); Assert.AreEqual(itemType.Name, inventoryItemTypeVersions[1].Name); Assert.AreEqual(itemType.BaseUnitOfMeasure, inventoryItemTypeVersions[1].BaseUnitOfMeasure); Assert.AreEqual(itemType.Comment, inventoryItemTypeVersions[1].Comment); Assert.AreEqual(itemType.CostingMethod, inventoryItemTypeVersions[1].CostingMethod); Assert.AreEqual(itemType.Description, inventoryItemTypeVersions[1].Description); Assert.AreEqual(itemType.EformId, inventoryItemTypeVersions[1].EformId); Assert.AreEqual(itemType.GrossWeight, inventoryItemTypeVersions[1].GrossWeight); Assert.AreEqual(itemType.GtinEanUpc, inventoryItemTypeVersions[1].GtinEanUpc); Assert.AreEqual(itemType.LastPhysicalInventoryDate, inventoryItemTypeVersions[1].LastPhysicalInventoryDate); Assert.AreEqual(itemType.NetWeight, inventoryItemTypeVersions[1].NetWeight); Assert.AreEqual(itemType.No, inventoryItemTypeVersions[1].No); Assert.AreEqual(itemType.ProfitPercent, inventoryItemTypeVersions[1].ProfitPercent); Assert.AreEqual(itemType.Region, inventoryItemTypeVersions[1].Region); Assert.AreEqual(itemType.RiskDescription, inventoryItemTypeVersions[1].RiskDescription); Assert.AreEqual(itemType.SalesUnitOfMeasure, inventoryItemTypeVersions[1].SalesUnitOfMeasure); Assert.AreEqual(itemType.StandardCost, inventoryItemTypeVersions[1].StandardCost); Assert.AreEqual(itemType.Usage, inventoryItemTypeVersions[1].Usage); Assert.AreEqual(itemType.UnitVolume, inventoryItemTypeVersions[1].UnitVolume); Assert.AreEqual(itemType.UnitPrice, inventoryItemTypeVersions[1].UnitPrice); Assert.AreEqual(itemType.UnitCost, inventoryItemTypeVersions[1].UnitCost); Assert.AreEqual(itemType.Id, inventoryItemTypeVersions[1].ItemTypeId); Assert.AreEqual(Constants.WorkflowStates.Removed, inventoryItemTypeVersions[1].WorkflowState); Assert.AreEqual(itemType.WorkflowState, inventoryItemTypeVersions[1].WorkflowState); Assert.AreEqual(2, inventoryItemTypeVersions[1].Version); }