private void LoadPatient(int patientId) { if (patientId == 0) // newly entry { PatientInfo = new PatientInfoViewModel(new tPatient()); PatientAddressInfo = new PatientAddressViewModel(new tAddress()); } else // Modification need to existing patient; { DB_SERVER _db = new DataLayer.DB_SERVER(); var patientInfo = _db.Patient.FirstOrDefault(e => e.PatientId == patientId); var patientAddress = _db.Address.FirstOrDefault(e => e.PatientId == patientId); PatientInfo = (patientInfo != null) ? new PatientInfoViewModel(patientInfo) : new PatientInfoViewModel(new tPatient()); PatientAddressInfo = (patientAddress != null) ? new PatientAddressViewModel(patientAddress) : new PatientAddressViewModel(new tAddress()); PatientAddressInfo.PatientId = PatientInfo.PatientId; } }