示例#1
0
        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();
 }
示例#3
0
 public EWLRepository()
 {
     Lb = new LbDemoContext();
 }
示例#4
0
 public BMICalculatorRepository()
 {
     Lbd = new LbDemoContext();
 }
示例#5
0
 public WeightRepository()
 {
     Lb  = new LapbaseContext();
     Lbd = new LbDemoContext();
 }