private async void AddUserBtn_Click(object sender, RoutedEventArgs e) { try { AddAdmissionBtn.IsEnabled = false; int? patientId = ((Patient)PatientListBox.SelectedItem)?.Id; int? wardId = ((Ward)WardListBox.SelectedItem)?.Id; int? doctorId = ((Doctor)DoctorListBox.SelectedItem)?.Id; DateTime?dateOfReceipt = DateOfReceiptPicker.SelectedDate; string diagnosis = DiagnosisTextBox.Text; if (!patientId.HasValue) { throw new ArgumentNullException($"'{nameof(patientId)}' is incorrect"); } if (!wardId.HasValue) { throw new ArgumentNullException($"'{nameof(wardId)}' is incorrect"); } if (!doctorId.HasValue) { throw new ArgumentNullException($"'{nameof(doctorId)}' is incorrect"); } if (!dateOfReceipt.HasValue || dateOfReceipt.Value > DateTime.Now) { throw new ArgumentNullException($"'{nameof(dateOfReceipt)}' is incorrect"); } if (string.IsNullOrWhiteSpace(diagnosis)) { throw new ArgumentNullException($"'{nameof(diagnosis)}' is incorrect"); } Admission requestAdmission = new Admission { PatientId = patientId.Value, WardId = wardId.Value, DoctorId = doctorId.Value, DateOfReceipt = dateOfReceipt.Value, Diagnosis = diagnosis }; string request = tcpService.SerializeAddAdmissionRequest(requestAdmission, SingletoneObj.User); byte[] data = await tcpService.CodeStreamAsync(request); await SingletoneObj.Stream.WriteAsync(data, 0, data.Length); string response = await tcpService.DecodeStreamAsync(SingletoneObj.Stream); var responseArgs = response.Split(';'); if (responseArgs.Length > 1 && responseArgs[0].Contains("500")) { throw new ArgumentException(responseArgs[1]); } this.Close(); } catch (Exception ex) { AddAdmissionBtn.IsEnabled = true; StatusLabel.Content = "Status: " + ex.Message; } }