Exemple #1
0
        private void btn_Disaster(object sender, RoutedEventArgs e)
        {
            DisasterPage disasterPage = new DisasterPage(userInfoData);

            mainFrame.Navigate(disasterPage);
        }
        private void btn_donateClick(object sender, RoutedEventArgs e)
        {
            if (disSelect == "")
            {
                MessageBox.Show("You have to choose specific disaster!");
                return;
            }
            if (txt_amount.Text == "")
            {
                MessageBox.Show("You have to insert the amount for donation!");
                return;
            }
            if (usernId == 0)
            {
                MessageBox.Show("You have to log in before donation!");
                return;
            }
            decimal amount = 0;

            amount = decimal.Parse(txt_amount.Text);



            if (amount > userAcc.Amount)
            {
                MessageBox.Show("You don't haave enough money. Change the amount!");
                return;
            }

            //bool donate=bankClient.donateToSpecificDisaster(amount, userAcc, disasterAcc);
            BankAccountService.BankAccountServiceClient bankCliente = new BankAccountService.BankAccountServiceClient();
            userAcc.Amount = userAcc.Amount - amount;
            bool updatedUserAcc = bankCliente.Update(userAcc);

            if (!updatedUserAcc)
            {
                MessageBox.Show("Failed donation!It can not update user account! Your page will be refreshed!");
                this.Content = null;
                DisasterPage refreshPage = new DisasterPage(userInfoData);
                NavigationService.Navigate(refreshPage);
                return;
            }
            userAcc            = bankCliente.GetBankAccountById(userBankAccId);
            disasterAcc.Amount = disasterAcc.Amount + amount;
            bool updatedDisasterAcc = bankCliente.Update(disasterAcc);

            if (!updatedDisasterAcc)
            {
                MessageBox.Show("Failed donation!It can not update disaster account! Your page will be refreshed!");
                this.Content = null;
                DisasterPage refreshPage = new DisasterPage(userInfoData);
                NavigationService.Navigate(refreshPage);
                return;
            }
            disasterAcc = bankCliente.GetBankAccountById(disasterAcc.AccountId);
            if (updatedDisasterAcc == true && updatedUserAcc == true)
            {
                MessageBox.Show("Donation is succesful!");
            }

            txt_amount.Text = "";
        }