示例#1
0
        private void EditMaterial(Object parameter)
        {
            try
            {
                IsEditingMaterialAllowed = false;
                var editableMaterial      = EditableJewelryMaterials.Find(x => x.ToString() == ChosenMaterial);
                var editableMaterialIndex = EditableJewelryMaterials.FindIndex(x => x.ToString() == ChosenMaterial);

                if (editableMaterial == null)
                {
                    MessageBox.Show($"Choose one of the materials from the dropdown menu.");
                    IsEditingMaterialAllowed = true;
                    return;
                }


                OnEditMaterial();

                addMaterialsVm.AlterMaterial(ref editableMaterial, () => OnMaterialEdited());

                EditableJewelryMaterials.RemoveAt(editableMaterialIndex);
                EditableJewelryMaterials.Add(editableMaterial);

                EditableJewelryMaterialsUI.RemoveAt(editableMaterialIndex);
                EditableJewelryMaterialsUI.Add(editableMaterial);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Wrong data was provided. Can't add that material. Detailed Error: {ex.Message}");
                OnMaterialEdited();
                IsEditingMaterialAllowed = true;
            }
        }
示例#2
0
        private void DeleteMaterial(object p)
        {
            if (string.IsNullOrEmpty(ChosenMaterial))
            {
                MessageBox.Show("Please choose a material from the list.");
                return;
            }

            try
            {
                var removalIndex = EditableJewelryMaterials.FindIndex(x => x.ToString() == ChosenMaterial);
                EditableJewelryMaterials.RemoveAt(removalIndex);
                EditableJewelryMaterialsUI.RemoveAt(removalIndex);
                MessageBox.Show($"Successfully removed.");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Could not remove material. Reason: {ex.Message}");
            }
        }