private void SaveButton_Click(object sender, EventArgs e) { if (!Validation.IsAllValid(Detail.Controls)) { return; } using (var repository = new SupplyRepository()) { if (supplyID > 0) { var supply = repository.GetSupply(supplyID); supply.Delivered = DeliveredDatePicker.Value.Date; supply.SupplierName = SupplierNameTextBox.Text; supply.Description = DescriptionTextBox.Text; repository.UpdateSupply(supply); repository.Commit(); supplyID = supply.ID; } else { var supply = new Supply { ID = (int)IDTextBox.Text.AsInt(), Delivered = DeliveredDatePicker.Value.Date, SupplierName = SupplierNameTextBox.Text, Description = DescriptionTextBox.Text }; repository.InsertSupply(supply); repository.Commit(); supplyID = supply.ID; } } ViewSupplyDetailTab(supplyID, false); }