public override int SaveChanges() { LbDemoContext lb = new LbDemoContext(); var entities = ChangeTracker.Entries().Where(x => x.Entity is BaseClass && (x.State == EntityState.Added || x.State == EntityState.Modified)); //get username from session or authentication var currentUsername = ""; foreach (var entity in entities) { if (entity.Entity is Food) { long patientId = ((Food)entity.Entity).PatientID; var patient = lb.tblPatients.Where(a => a.Patient_Id == patientId).FirstOrDefault(); currentUsername = patient.Firstname; } if (entity.Entity is Exercise) { long patientId = ((Exercise)entity.Entity).PatientID; var patient = lb.tblPatients.Where(a => a.Patient_Id == patientId).FirstOrDefault(); currentUsername = patient.Firstname; } if (entity.Entity is Weight) { long patientId = ((Weight)entity.Entity).PatientID; var patient = lb.tblPatients.Where(a => a.Patient_Id == patientId).FirstOrDefault(); currentUsername = patient.Firstname; } if (entity.State == EntityState.Added) { ((BaseClass)entity.Entity).CreatedAt = DateTime.Now; ((BaseClass)entity.Entity).CreatedBy = currentUsername; } ((BaseClass)entity.Entity).ModifiedAt = DateTime.Now; ((BaseClass)entity.Entity).ModifiedBy = currentUsername; } return(base.SaveChanges()); }
public PatientDemographicRepository() { Lb = new LbDemoContext(); }
public EWLRepository() { Lb = new LbDemoContext(); }
public BMICalculatorRepository() { Lbd = new LbDemoContext(); }
public WeightRepository() { Lb = new LapbaseContext(); Lbd = new LbDemoContext(); }