public int AddPatient(Patient model ) { try { entities.Patients.Add(model); entities.SaveChanges(); return model.PatientId; } catch (Exception x) { throw x; } }
public bool UpdatePatient(Patient model) { try { Patient patient = entities.Patients.Where(x => x.PatientId == model.PatientId).SingleOrDefault(); if (patient != null) { entities.Entry(patient).CurrentValues.SetValues(model); entities.SaveChanges(); return true; } else { return false; } } catch (Exception x) { throw x; } }
private void btnSavePatient_Click(object sender, EventArgs e) { bool result = true; if (txtFirstName.Text.Trim() == "") { MessageBox.Show("Enter first name"); return; } try { Patient patient = new Patient(); patient.Prefix = ddlPrefix.SelectedItem == null ? "" : ddlPrefix.SelectedItem.Text; patient.FirstName = txtFirstName.Text.Trim(); patient.MiddleName = txtMiddleName.Text.Trim(); patient.LastName = txtLastName.Text.Trim(); patient.DOB = DOB.Value; patient.Gender = chkMale.Checked ? "M" : "F"; patient.Address = txtAddress.Text; patient.Mobile = txtMobile.Text.Trim(); patient.HomePhone = txtPhone.Text.Trim(); patient.Email = txtEmail.Text; patient.HospitalId = Convert.ToInt32(ddlHospital.SelectedValue.ToString()); patient.CreatedOn = DateTime.Now; patient.UpdatedOn = DateTime.Now; patient.IsSmoker = false; patient.IsAlchoholic = false; PatientData patientObject = new PatientData(); _patientid = patientObject.AddPatient(patient); } catch (Exception x) { FileLogger.LogError(x); return; } if (result) { txtFirstName.Text = ""; txtLastName.Text = ""; txtMiddleName.Text = ""; txtMobile.Text = ""; txtPhone.Text = ""; txtAddress.Text = ""; txtEmail.Text = ""; //Make Dirctories DataFolder.CreatePatientDataFolders(_patientid); //Open Patient hub new PatientForm(_patientid).ShowDialog(); } else { btnSavePatient.Visible = true; MessageBox.Show("Error adding a patient : Please contact support"); return; } }