public AddEditDiagnosticModal(Model.Diagnostic selectedDiagnostic, Model.Area selectedArea) { this.InitializeComponent(); _selectedArea = selectedArea; _selectedDiagnostic = selectedDiagnostic; _isUpdateDiagnostic = selectedDiagnostic != null; btnSearchImage1.Tag = btnRemoveImage1.Tag = diagnosticImage1; btnSearchImage2.Tag = btnRemoveImage2.Tag = diagnosticImage2; if (_isUpdateDiagnostic) PrepareWindowForUpdates(); }
private void btnAddUpdate_Click(object sender, System.Windows.RoutedEventArgs e) { string diagnosticName = txtDiagnosticName.Text.Trim().Replace("|", string.Empty); string diagnosticDescription = txtDiagnosticDescription.Text.Trim(); string picturePath1 = diagnosticImage1.ToolTip == null ? null : diagnosticImage1.ToolTip.ToString(); string picturePath2 = diagnosticImage2.ToolTip == null ? null : diagnosticImage2.ToolTip.ToString(); if (string.IsNullOrEmpty(diagnosticName)) { MessageBox.Show("Ingrese el nombre del diagnóstico", "Información", MessageBoxButton.OK, MessageBoxImage.Information); return; } else if (_isUpdateDiagnostic) { _selectedDiagnostic.Name = diagnosticName; _selectedDiagnostic.Description = diagnosticDescription; _selectedDiagnostic.PicturePath1 = picturePath1; _selectedDiagnostic.PicturePath2 = picturePath2; if (Controllers.BusinessController.Instance.Update<Model.Diagnostic>(_selectedDiagnostic)) this.Close(); else MessageBox.Show("No se pudo actualizar el diagnóstico", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { Model.Diagnostic diagnosticToAdd = new Model.Diagnostic() { AreaId = _selectedArea.AreaId, Name = diagnosticName, Description = diagnosticDescription, PicturePath1 = picturePath1, PicturePath2 = picturePath2, CreatedDate = DateTime.Now, IsDeleted = false }; if (Controllers.BusinessController.Instance.Add<Model.Diagnostic>(diagnosticToAdd)) this.Close(); else MessageBox.Show("No se pudo agregar el diagnóstico", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }