/// <summary> /// Service method to create patient /// </summary> /// <param name="patient">patient model</param> /// <returns>true or false</returns> public bool Create(PatientEntity patient) { using (var context = new FHIRDbContext()) { context.Patients.Add(patient); return(context.SaveChanges() > 0); } }
/// <summary> /// Method to delete a patient /// </summary> /// <param name="id">patient id</param> /// <returns>true / false</returns> public bool DeletefromDB(int id) { using (var context = new FHIRDbContext()) { var patient = context.Patients.Find(id); context.Patients.Remove(patient); return(context.SaveChanges() > 0); } }
/// <summary> /// Service method to update patient /// </summary> /// <param name="patient">patient</param> /// <returns>true / false</returns> public bool Update(PatientEntity patient) { using (var context = new FHIRDbContext()) { context.Patients.Attach(patient); context.Entry(patient).State = EntityState.Modified; return(context.SaveChanges() > 0); } }
/// <summary> /// Method to soft delete a patient /// </summary> /// <param name="id">patient id</param> /// <returns>true / false</returns> public bool Delete(int id) { using (var context = new FHIRDbContext()) { var patient = context.Patients.Find(id); patient.SoftDelete = true; context.Patients.Attach(patient); context.Entry(patient).State = EntityState.Modified; return(context.SaveChanges() > 0); } }
/// <summary> /// Service method to batch create patient /// </summary> /// <param name="patient">patient list</param> /// <returns>true or false</returns> public bool BatchCreate(List <PatientEntity> patientlist) { using (var context = new FHIRDbContext()) { try { foreach (var row in patientlist) { context.Patients.Add(row); } return(context.SaveChanges() > 0); } catch (Exception ex) { return(false); } } }