示例#1
0
        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);
            }
        }