private void ConfirmSignOblBtn_Click(object sender, EventArgs e) { /****************************************************************************************** ** Get fields in values ** ******************************************************************************************/ // Get values of NameOfOblSignOblField var oblName = NameOfOblSignOblField.Text; // Get values of ClientNumberSignOblField var clientNumber = int.Parse(ClientNumberSignOblField.Text); // Get values of CategoryOblSignOblField var category = CategoryOblSignOblField.Text; // Get values of HasToPaidFieldSignObl var hasPayde = decimal.Parse(HasToPaidFieldSignObl.Text); /****************************************************************************************** ** Create Services ** ******************************************************************************************/ // Create client service ClientRepository client = new ClientRepository(); // Create Obligation service ObligationsRepository obl = new ObligationsRepository(); var currentClient = client.GetClients().FirstOrDefault(c => c.client_serial_number == clientNumber); currentClient.Obligations.Add( obl.AddObligations(new Obligations { Category = new Category() { category_name = category }, obligation_name = oblName, obligation_payments = hasPayde }) ); NameOfOblSignOblField.Text = ""; ClientNumberSignOblField.Text = ""; CategoryOblSignOblField.Text = ""; HasToPaidFieldSignObl.Text = ""; }
private void ConfirmPaymentsButton_Click(object sender, EventArgs e) { { /****************************************************************************************** ** Get fields in values ** ******************************************************************************************/ // getting values in lientNumberPaymentsField var clientNumber = int.Parse(ClientNumberPaymentsField.Text); // getting values in PayAmountPaymentField var paymentSum = decimal.Parse(PayAmountPaymentField.Text); // getting values IdOfObligation field var numOfObligation = int.Parse(IdOfObligationPaymentField.Text); // getting values NameOfObligPaymentsField var nameOfObl = NameOfObligPaymentsField.Text; /****************************************************************************************** ** Create Repository ** ******************************************************************************************/ // Creating repository of client ClientRepository client = new ClientRepository(); // Creating repository of obligation ObligationsRepository obligation = new ObligationsRepository(); // Creating repository of payment PaymentsRepository payment = new PaymentsRepository(); /****************************************************************************************** ** Processing of obligation and user ** ******************************************************************************************/ // Get current obligation var currentObl = obligation.GetObligations().FirstOrDefault(o => o.obligation_number == numOfObligation); // Get current user var currentCli = client.GetClients().FirstOrDefault(c => c.client_serial_number == clientNumber); // Check if fields are empty if (ClientNumberPaymentsField.Text.Length == 0 || PayAmountPaymentField.Text.Length == 0 || IdOfObligationPaymentField.Text.Length == 0 || NameOfObligPaymentsField.Text.Length == 0) { MessageBox.Show("Не сте въвели някое от полетата"); } else { // Adding a payments currentObl.payments.Add(payment.AddPayments(new payments { amount_of_payment = paymentSum, date_of_payment = DateTime.Now.Date } )); // Checking if client exists it will add obligation if (currentCli?.Obligations.FirstOrDefault(o => o.obligation_number == numOfObligation) == null) { // Add obligation in the client currentCli.Obligations.Add( currentObl); } else { // getting obligation number as index var index = currentCli.Obligations.ToList().IndexOf( currentCli.Obligations.ToList().FirstOrDefault( o => o.obligation_number == numOfObligation)); // remove old obligation currentCli.Obligations.ToList().RemoveAt(index); // add new obligation currentCli.Obligations.ToList().Insert( index, currentObl); } } } }