private void btnFind_Click(object sender, RoutedEventArgs e) { try { using (var riskAssessmentClient = new RiskAssessmentServiceClient()) { var result = riskAssessmentClient.GetRiskAssessment(supRefTxt.Text); if (result == null) { MessageBox.Show("Risk Assessment not found"); return; } laTxt.Text = result.LocalAuthority; supNameTxt.Text = result.SupplyName; dteCreated.SelectedDate = result.DateCreated; EnableTextBoxes(); supRefTxt.IsEnabled = false; App.Mode = Mode.Update; SetButtons(); } } catch (Exception) { // Do nothing. Perfect demo ;) } finally { } }
private void btnSave_Click(object sender, RoutedEventArgs e) { string resultMessage = "Action failed. Please validate data and try again"; try { var riskAssessment = new RiskAssessment { SupplyName = supNameTxt.Text, SupplyReference = supRefTxt.Text, LocalAuthority = laTxt.Text, DateCreated = dteCreated.SelectedDate.Value }; using (var riskAssessmentClient = new RiskAssessmentServiceClient()) { RiskAssessment result = null; switch (App.Mode) { case Mode.Create: result = riskAssessmentClient.CreateRiskAssessment(riskAssessment); break; case Mode.Update: result = riskAssessmentClient.UpdateRiskAssessment(riskAssessment); break; default: break; } if (result != null) { resultMessage = "Risk Assessment saved"; App.RiskAssessment = result; } } } catch { // Do nothing. Perfect demo ;) } finally { MessageBox.Show(resultMessage); } }