protected void saveButton_Click(object sender, EventArgs e) { var disease = diseases.Value.Split(','); var medicine = medicines.Value.Split(','); var dose = doses.Value.Split(','); var doseRule = meals.Value.Split(','); var quantity = quantities.Value.Split(','); var note = notes.Value.Split(','); var date = dateTextBox.Value; var doctorId = Convert.ToInt32(doctorDropDownList.SelectedValue); var observation = observationTextBox.Text; string[] districtName = addressTextBox.Text.Split(' '); diseases.Value = medicines.Value = doses.Value = meals.Value = quantities.Value = notes.Value = ""; Patient aPatient = new Patient() { VoterId = voterIdTextBox.Text, DistrictId = aDistrictManager.Find(districtName[districtName.Length - 1]).Id }; aPatientManager.Save(aPatient); int serviceId = aPatientManager.GetLastServiceTakenId(); for (int i = 0; i < medicine.Length - 1; i++) { Treatment aTreatment = new Treatment() { Observation = observation, Date = Convert.ToDateTime(date), DoctorId = doctorId, DiseaseId = aDiseaseManager.Find(disease[i]).Id, MedicineId = aMedicineManager.Find(medicine[i]).Id, Dose = dose[i], Quantity = Convert.ToInt32(quantity[i]), Note = note[i], DoseRules = doseRule[i], CenterId = Convert.ToInt32(Session["centerId"]), ServiceTakenId = serviceId }; aTreatmentManager.Save(aTreatment); } }