Ejemplo n.º 1
0
        } // Create


        public async Task UpdateAsync( Guid id, GlucoseEntry glucoseEntry )
        {
            var dbGlucoseEntry = await ReadAsync( id );
            if( dbGlucoseEntry != null )
            {
                if( Config.AuditingOn )
                {
                    var auditChange = new AuditChange();
                    auditChange.CreateAuditTrail( AuditActionType.UPDATE, dbGlucoseEntry.Id.ToString(), dbGlucoseEntry, glucoseEntry );
                    await _auditRepo.CreateAsync( auditChange );

                } // if

                dbGlucoseEntry.UserName = glucoseEntry.UserName;
                dbGlucoseEntry.Patient = glucoseEntry.Patient;
    			dbGlucoseEntry.Measurement = glucoseEntry.Measurement;
    			dbGlucoseEntry.BeforeAfter = glucoseEntry.BeforeAfter;
    			dbGlucoseEntry.WhichMeal = glucoseEntry.WhichMeal;
    			dbGlucoseEntry.CreatedAt = glucoseEntry.CreatedAt;
                dbGlucoseEntry.UpdatedAt = glucoseEntry.UpdatedAt;
                dbGlucoseEntry.Timestamp = glucoseEntry.Timestamp;
                _db.Entry( dbGlucoseEntry ).State = EntityState.Modified;
                await _db.SaveChangesAsync();
                return;
            }

        } // UpdateAsync
        } // Create


        public async Task UpdateAsync( Guid id, ExerciseEntry exerciseEntry )
        {
            var oldExerciseEntry = await ReadAsync( id );
            if( oldExerciseEntry != null )
            {
                if( Config.AuditingOn )
                {
                    var auditChange = new AuditChange();
                    if( !auditChange.CreateAuditTrail( AuditActionType.UPDATE, exerciseEntry.Id.ToString(), oldExerciseEntry, exerciseEntry ) )
                        await _auditRepo.CreateAsync( auditChange );

                } // if

                oldExerciseEntry.UserName = exerciseEntry.UserName;
    			oldExerciseEntry.Patient = exerciseEntry.Patient;
    			oldExerciseEntry.Name = exerciseEntry.Name;
    			oldExerciseEntry.Minutes = exerciseEntry.Minutes;
    			oldExerciseEntry.CreatedAt = exerciseEntry.CreatedAt;
                oldExerciseEntry.UpdatedAt = exerciseEntry.UpdatedAt;
                oldExerciseEntry.Timestamp = exerciseEntry.Timestamp;
                _db.Entry( oldExerciseEntry ).State = EntityState.Modified;
                await _db.SaveChangesAsync();
                return;
            }

        } // UpdateAsync
        public void SeedRoles()
        {
            _db.Database.EnsureCreated();
            AuditChange     change;
            ApplicationRole role;

            if (!_db.Roles.Any(r => r.Name == Roles.DOCTOR))
            {
                Debug.WriteLine("Creating Doctor role...");
                role = new ApplicationRole
                {
                    Name        = Roles.DOCTOR,
                    Description = "A role allowing doctors to view their patients' statistics.",
                    CreatedDate = DateTime.Now
                };
                _roleManager.CreateAsync(role);
                if (Config.AuditingOn)
                {
                    change = new AuditChange();
                    change.CreateAuditTrail(AuditActionType.CREATE, role.Id, new ApplicationRole(), role);
                    _auditRepository.CreateAsync(change);
                }
            }

            if (!_db.Roles.Any(r => r.Name == Roles.PATIENT))
            {
                Debug.WriteLine("Creating Patient role...");
                role = new ApplicationRole
                {
                    Name        = Roles.PATIENT,
                    Description = "A patient who is registered to a doctor.",
                    CreatedDate = DateTime.Now
                };
                _roleManager.CreateAsync(role);
                if (Config.AuditingOn)
                {
                    change = new AuditChange();
                    change.CreateAuditTrail(AuditActionType.CREATE, role.Id, new ApplicationRole(), role);
                    _auditRepository.CreateAsync(change);
                }
            }

            if (!_db.Roles.Any(r => r.Name == Roles.DEVELOPER))
            {
                Debug.WriteLine("Creating Developer role...");
                role = new ApplicationRole
                {
                    Name        = Roles.DEVELOPER,
                    Description = "A developer role allowing heightened permissions.",
                    CreatedDate = DateTime.Now
                };
                _roleManager.CreateAsync(role);
                if (Config.AuditingOn)
                {
                    change = new AuditChange();
                    change.CreateAuditTrail(AuditActionType.CREATE, role.Id, new ApplicationRole(), role);
                    _auditRepository.CreateAsync(change);
                }
            }
        } // SeedRoles
Ejemplo n.º 4
0
        } // CreateAsync

        public async Task UpdateAsync(Guid id, HIPAAPrivacyNotice privacyNotice)
        {
            var dbNotice = await ReadAsync(id);

            if (dbNotice != null)
            {
                if (Config.AuditingOn)
                {
                    var auditChange = new AuditChange();
                    auditChange.CreateAuditTrail(AuditActionType.UPDATE, privacyNotice.Id.ToString(), dbNotice, privacyNotice);
                    await _auditRepo.CreateAsync(auditChange);
                } // if

                dbNotice.CreatedAt  = privacyNotice.CreatedAt;
                dbNotice.NoticeText = privacyNotice.NoticeText;
                dbNotice.Title      = privacyNotice.Title;
                dbNotice.UpdatedAt  = DateTime.Now;
                dbNotice.Version    = privacyNotice.Version;

                _db.Entry(dbNotice).State = EntityState.Modified;
                await _db.SaveChangesAsync();
            } // if

            return;
        } // UpdateAsync
        } // CreateAsync

        public async Task UpdateAsync(string userName, Developer developer)
        {
            var oldDeveloper = await ReadAsync(userName);

            if (oldDeveloper != null)
            {
                if (Config.AuditingOn)
                {
                    var auditChange = new AuditChange();
                    if (!auditChange.CreateAuditTrail(AuditActionType.UPDATE, developer.Id, oldDeveloper, developer))
                    {
                        await _auditRepo.CreateAsync(auditChange);
                    }
                } // if

                if (!string.IsNullOrEmpty(developer.Title))
                {
                    oldDeveloper.Title = developer.Title;
                }

                _db.Entry(oldDeveloper).State = EntityState.Modified;
                await _db.SaveChangesAsync();

                await _userRepo.UpdateAsync(userName, developer);

                return;
            }
        } // UpdateAsync
        } // CreateAsync


        public async Task UpdateAsync( Guid id, MealItem mealItem )
        {
            var dbMealItem = await ReadAsync( id );
            if ( dbMealItem != null )
            {
                if( Config.AuditingOn )
                {
                    var auditChange = new AuditChange();
                    auditChange.CreateAuditTrail( AuditActionType.UPDATE, mealItem.Id.ToString(), dbMealItem, mealItem );
                    await _auditRepo.CreateAsync( auditChange );

                } // if

                dbMealItem.Name = mealItem.Name;
                dbMealItem.Carbs = mealItem.Carbs;
                dbMealItem.Servings = mealItem.Servings;
                //oldMealItem.Meal = mealItem.Meal;
                //oldMealItem.MealId = mealItem.MealId;
                dbMealItem.UpdatedAt = mealItem.UpdatedAt;
                //oldMealItem.UpdatedAt = mealItem.UpdatedAt;
                _db.Entry( dbMealItem.Meal ).State = EntityState.Unchanged;
                _db.Entry( dbMealItem ).State = EntityState.Modified;
                await _db.SaveChangesAsync();
                return;
            }

        } // UpdateAsync
Ejemplo n.º 7
0
 public virtual void Dispose()
 {
     this.Clear();
     this.IsAdmin  = false;
     this.IsSystem = false;
     this.RoleNames?.Clear();
     this.RoleIds?.Clear();
     this.AuditChange = null;
 }
Ejemplo n.º 8
0
        } // CreateAsync

        public async Task UpdateAsync(string username, ApplicationUser applicationUser)
        {
            var dbUser = await ReadAsync(username);

            if (dbUser != null)
            {
                if (Config.AuditingOn)
                {
                    var auditChange = new AuditChange();
                    auditChange.CreateAuditTrail(AuditActionType.UPDATE, applicationUser.Id, dbUser, applicationUser);
                    await _auditRepo.CreateAsync(auditChange);
                }

                if (!string.IsNullOrEmpty(applicationUser.Address1))
                {
                    dbUser.Address1 = applicationUser.Address1;
                }
                if (!string.IsNullOrEmpty(applicationUser.Address2))
                {
                    dbUser.Address2 = applicationUser.Address2;
                }
                if (!string.IsNullOrEmpty(applicationUser.City))
                {
                    dbUser.City = applicationUser.City;
                }
                if (!string.IsNullOrEmpty(applicationUser.Email))
                {
                    dbUser.Email = applicationUser.Email;
                }
                if (!string.IsNullOrEmpty(applicationUser.FirstName))
                {
                    dbUser.FirstName = applicationUser.FirstName;
                }
                if (!string.IsNullOrEmpty(applicationUser.LastName))
                {
                    dbUser.LastName = applicationUser.LastName;
                }
                if (!string.IsNullOrEmpty(applicationUser.PhoneNumber))
                {
                    dbUser.PhoneNumber = applicationUser.PhoneNumber;
                }
                if (!string.IsNullOrEmpty(applicationUser.State))
                {
                    dbUser.State = applicationUser.State;
                }
                dbUser.Zip1 = applicationUser.Zip1;
                dbUser.Zip2 = applicationUser.Zip2;

                _db.Entry(dbUser).State = EntityState.Modified;
                await _db.SaveChangesAsync();

                return;
            } // if
        }     // UpdateAsync
Ejemplo n.º 9
0
        } // ReadAll

        public async Task <ApplicationUser> CreateAsync(ApplicationUser applicationUser)
        {
            _db.Users.Add(applicationUser);
            await _db.SaveChangesAsync();

            if (Config.AuditingOn)
            {
                var auditChange = new AuditChange();
                auditChange.CreateAuditTrail(AuditActionType.CREATE, applicationUser.Id, new ApplicationUser(), applicationUser);
                await _auditRepo.CreateAsync(auditChange);
            }
            return(applicationUser);
        } // CreateAsync
        } // ReadAll

        public async Task <Developer> CreateAsync(Developer developer)
        {
            _db.Developers.Add(developer);
            await _db.SaveChangesAsync();

            if (Config.AuditingOn)
            {
                var auditChange = new AuditChange();
                auditChange.CreateAuditTrail(AuditActionType.CREATE, developer.Id, new Doctor(), developer);
                await _auditRepo.CreateAsync(auditChange);
            } // if

            return(developer);
        } // CreateAsync
        } // DeleteAsync

        public ExerciseEntry Create(ExerciseEntry exerciseEntry)
        {
            _db.ExerciseEntries.Add(exerciseEntry);
            _db.SaveChanges();

            if( Config.AuditingOn )
            {
                var auditChange = new AuditChange();
                auditChange.CreateAuditTrail( AuditActionType.CREATE, exerciseEntry.Id.ToString(), new ExerciseEntry(), exerciseEntry );
                _auditRepo.CreateAsync( auditChange );

            } // if

            return exerciseEntry;
        }// ExerciseEntry Create
        } // ReadAll

        public async Task <AuditChange> CreateAsync(AuditChange auditChange)
        {
            //_db.AuditChanges.Add( auditChange );
            //await _db.SaveChangesAsync();
            await auditClient.CreateDocumentAsync(
                UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), auditChange
                );

            //if(auditChange.Deltas.Count > 0)
            //foreach(var delta in auditChange.Deltas)
            //    await auditClient.CreateDocumentAsync(
            //    UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), delta
            //    );
            return(auditChange);
        } // CreateAsync
Ejemplo n.º 13
0
        } // ReadAll


        public async Task<GlucoseEntry> CreateAsync( GlucoseEntry glucoseEntry )
        {
            _db.GlucoseEntries.Add( glucoseEntry );
            await _db.SaveChangesAsync();

            if( Config.AuditingOn )
            {
                var auditChange = new AuditChange();
                auditChange.CreateAuditTrail( AuditActionType.CREATE, glucoseEntry.Id.ToString(), new GlucoseEntry(), glucoseEntry );
                await _auditRepo.CreateAsync( auditChange );

            } // if

            return glucoseEntry;

        } // Create
Ejemplo n.º 14
0
        } // ReadAll


        public async Task<MealEntry> CreateAsync( MealEntry mealentry )
        {
            _db.MealEntries.Add( mealentry );
            await _db.SaveChangesAsync();

            if( Config.AuditingOn )
            {
                var auditChange = new AuditChange();
                auditChange.CreateAuditTrail( AuditActionType.CREATE, mealentry.Id.ToString(), new MealEntry(), mealentry );
                await _auditRepo.CreateAsync( auditChange );

            } // if

            return mealentry;

        } // Create
Ejemplo n.º 15
0
        } // ReadAll

        public async Task <HIPAAPrivacyNotice> CreateAsync(HIPAAPrivacyNotice privacyNotice)
        {
            privacyNotice.CreatedAt = DateTime.Now;
            privacyNotice.UpdatedAt = DateTime.Now;
            await _db.HIPAAPrivacyNotices.AddAsync(privacyNotice);

            await _db.SaveChangesAsync();

            if (Config.AuditingOn)
            {
                var auditChange = new AuditChange();
                auditChange.CreateAuditTrail(AuditActionType.CREATE, privacyNotice.Id.ToString(), new HIPAAPrivacyNotice(), privacyNotice);
                await _auditRepo.CreateAsync(auditChange);
            } // if

            return(privacyNotice);
        } // CreateAsync
Ejemplo n.º 16
0
        } // ReadAsync


        public async Task<Doctor> CreateAsync( Doctor doctor )
        {
            doctor.SecurityStamp = Guid.NewGuid().ToString();
            _db.Doctors.Add( doctor );
            await _db.SaveChangesAsync();

            if( Config.AuditingOn )
            {
                var auditChange = new AuditChange();
                auditChange.CreateAuditTrail( AuditActionType.CREATE, doctor.Id, new Doctor(), doctor );
                await _auditRepo.CreateAsync( auditChange );

            } // if

            return doctor;

        } // Create
        } // ReadAll


        public async Task<Patient> CreateAsync( Patient patient )
        {
            _db.Patients.Add( patient );
            _db.Entry( patient.PatientSignedHIPAANotice ).State = EntityState.Unchanged;
            await _db.SaveChangesAsync();

            if( Config.AuditingOn )
            {
                var auditChange = new AuditChange();
                auditChange.CreateAuditTrail( AuditActionType.CREATE, patient.Id, new Patient(), patient );
                await _auditRepo.CreateAsync( auditChange );

            } // if

            return patient;

        } // Create
Ejemplo n.º 18
0
        }     // UpdateAsync

        public async Task DeleteAsync(string username)
        {
            var user = await ReadAsync(username);

            if (user != null)
            {
                if (Config.AuditingOn)
                {
                    var auditChange = new AuditChange();
                    auditChange.CreateAuditTrail(AuditActionType.DELETE, user.Id, user, new ApplicationUser());
                    await _auditRepo.CreateAsync(auditChange);
                }

                _db.Users.Remove(user);
                await _db.SaveChangesAsync();
            }
            return;
        } // DeleteAsync
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            IServiceProvider provider = context.HttpContext.RequestServices;
            var controllerAction      = context.ActionDescriptor as ControllerActionDescriptor;
            var isAuditEnabled        = provider.GetAppSettings().AuditEnabled;

            if (isAuditEnabled)
            {
                DictionaryScoped dict        = provider.GetService <DictionaryScoped>();
                AuditChange      auditChange = new AuditChange();
                auditChange.FunctionName       = $"{context.Controller.GetType().ToDescription()}-{controllerAction.MethodInfo.ToDescription()}";
                auditChange.Action             = context.HttpContext.Request.Path;
                auditChange.Ip                 = context.HttpContext.GetClientIP();
                auditChange.BrowserInformation = context.HttpContext.Request.Headers["User-Agent"].ToString();
                auditChange.StartTime          = DateTime.Now;
                dict.AuditChange               = auditChange;
            }
        }
Ejemplo n.º 20
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            var controllerAction = context.ActionDescriptor as ControllerActionDescriptor;

            if (controllerAction.ControllerTypeInfo.HasAttribute <DisableAuditingAttribute>() == false || !controllerAction.MethodInfo.HasAttribute <DisableAuditingAttribute>() == false)
            {
                IServiceProvider provider = context.HttpContext.RequestServices;

                DictionaryScoped dict        = provider.GetService <DictionaryScoped>();
                AuditChange      auditChange = new AuditChange();
                auditChange.FunctionName       = $"{context.Controller.GetType().ToDescription()}-{controllerAction.MethodInfo.ToDescription()}";
                auditChange.Action             = context.HttpContext.Request.Path;
                auditChange.Ip                 = context.HttpContext.GetClientIP();
                auditChange.BrowserInformation = context.HttpContext.Request.Headers["User-Agent"].ToString();
                auditChange.StartTime          = DateTime.Now;
                dict.AuditChange               = auditChange;
            }
        }
        } // UpdateAsync

        public async Task DeleteAsync(string userName)
        {
            var developer = await ReadAsync(userName);

            if (developer != null)
            {
                if (Config.AuditingOn)
                {
                    var auditChange = new AuditChange();
                    auditChange.CreateAuditTrail(AuditActionType.DELETE, developer.Id, developer, new Doctor());
                    await _auditRepo.CreateAsync(auditChange);
                } // if

                _db.Developers.Remove(developer);
                await _db.SaveChangesAsync();
            }
            return;
        } // DeleteAsync
Ejemplo n.º 22
0
        } // UpdateAsync

        public async Task DeleteAsync(Guid id)
        {
            var notice = await ReadAsync(id);

            if (notice != null)
            {
                if (Config.AuditingOn)
                {
                    var auditChange = new AuditChange();
                    auditChange.CreateAuditTrail(AuditActionType.DELETE, notice.Id.ToString(), notice, new HIPAAPrivacyNotice());
                    await _auditRepo.CreateAsync(auditChange);
                } // if

                _db.HIPAAPrivacyNotices.Remove(notice);
                await _db.SaveChangesAsync();
            }
            return;
        }
        } // UpdateAsync


        public async Task DeleteAsync( Guid id )
        {
            var exerciseentry = await ReadAsync( id );
            if( exerciseentry != null )
            {
                if( Config.AuditingOn )
                {
                    var auditChange = new AuditChange();
                    auditChange.CreateAuditTrail( AuditActionType.DELETE, id.ToString(), exerciseentry, new ExerciseEntry() );
                    await _auditRepo.CreateAsync( auditChange );

                } // if

                _db.ExerciseEntries.Remove( exerciseentry );
                await _db.SaveChangesAsync();
            }
            return;

        } // DeleteAsync
        } // UpdateAsync


        public async Task DeleteAsync( string username )
        {
            if( Exists( username ) )
            {
                var patient = await ReadAsync( username );
                if( Config.AuditingOn )
                {
                    var auditChange = new AuditChange();
                    auditChange.CreateAuditTrail( AuditActionType.DELETE, patient.Id, patient, new Patient() );
                    await _auditRepo.CreateAsync( auditChange );

                } // if

                _db.Patients.Remove( patient );
                await _db.SaveChangesAsync();
            }
            return;

        } // DeleteAsync
Ejemplo n.º 25
0
        // *** Start programmer edit section *** (WinformShowAuditFormU CustomMembers)
        private TreeNode CreateTreeNodeForAuditChange(AuditChange change)
        {
            TreeNode newTreeNode = null;

            if (change != null)
            {
                var childNode = new List <TreeNode>();
                change.FieldsChanges.ForEach(x => childNode.Add(new TreeNode($"Field {x.Key} = {x.Value}")));
                if (change.MastersChanges.Any())
                {
                    var mastersNode = new List <TreeNode>();
                    change.MastersChanges.ForEach(x =>
                    {
                        var newMasterNode  = CreateTreeNodeForAuditChange(x.Value);
                        newMasterNode.Text = $"Master {x.Key} = {newMasterNode.Text}";
                        mastersNode.Add(newMasterNode);
                    });
                    childNode.Add(new TreeNode("Masters", mastersNode.ToArray()));
                }

                if (change.DetailsChanges.Any())
                {
                    var detailsNode = new List <TreeNode>();
                    change.DetailsChanges.ForEach(x =>
                    {
                        var newDetailNode  = CreateTreeNodeForAuditChange(x.Value);
                        newDetailNode.Text = $"Detail {x.Key} = {newDetailNode.Text}";
                        detailsNode.Add(newDetailNode);
                    });
                    childNode.Add(new TreeNode("Details", detailsNode.ToArray()));
                }

                newTreeNode =
                    new TreeNode($"PK = {change.ObjPrimaryKey}; Operation = {change.Operation}; Type = {change.Type};",
                                 childNode.ToArray());
            }
            else
            {
                newTreeNode = new TreeNode("NULL");
            }

            return(newTreeNode);
        }
        } // UpdateAsync


        public async Task DeleteAsync( Guid id )
        {
            var mealItem = await ReadAsync( id );
            if ( mealItem != null )
            {
                if( Config.AuditingOn )
                {
                    var auditChange = new AuditChange();
                    auditChange.CreateAuditTrail( AuditActionType.DELETE, mealItem.Id.ToString(), mealItem, new MealItem() );
                    await _auditRepo.CreateAsync( auditChange );

                } // if

                _db.MealItems.Remove( mealItem );
                await _db.SaveChangesAsync();
            }
            return;

        } // DeleteAsync
Ejemplo n.º 27
0
        } // UpdateAsync


        public async Task DeleteAsync( Guid id )
        {
            var glucoseEntry = await ReadAsync( id );
            if( glucoseEntry != null )
            {
                if( Config.AuditingOn )
                {
                    var auditChange = new AuditChange();
                    auditChange.CreateAuditTrail( AuditActionType.UPDATE, id.ToString(), glucoseEntry, new GlucoseEntry() );
                    await _auditRepo.CreateAsync( auditChange );
                }

                _db.GlucoseEntries.Remove( glucoseEntry );
                await _db.SaveChangesAsync();
            }

            return;

        } // DeleteAsync
Ejemplo n.º 28
0
        } // Create


        public async Task UpdateAsync( Guid id, MealEntry mealEntry )
        {
            var dbMealEntry = await ReadAsync( id );
            if( dbMealEntry != null )
            {
                if( Config.AuditingOn )
                {
                    var auditChange = new AuditChange();
                    auditChange.CreateAuditTrail( AuditActionType.UPDATE, mealEntry.Id.ToString(), dbMealEntry, mealEntry );
                    await _auditRepo.CreateAsync( auditChange );

                } // if

                dbMealEntry.UserName = mealEntry.UserName;
                dbMealEntry.Patient = mealEntry.Patient;
                dbMealEntry.TotalCarbs = mealEntry.TotalCarbs;
                dbMealEntry.CreatedAt = mealEntry.CreatedAt;
                dbMealEntry.UpdatedAt = mealEntry.UpdatedAt;
                dbMealEntry.Timestamp = mealEntry.Timestamp;
                //oldMealEntry.MealItems = mealEntry.MealItems;

                _db.Entry( mealEntry.MealItems ).State = EntityState.Unchanged;
                _db.Entry( dbMealEntry.MealItems ).State = EntityState.Unchanged;

                foreach( var mealItem in mealEntry.MealItems )
                    _db.Entry( mealItem ).State = EntityState.Unchanged;

                foreach( var mealItem in dbMealEntry.MealItems )
                    _db.Entry( mealItem ).State = EntityState.Unchanged;

                _db.Entry( dbMealEntry ).State = EntityState.Modified;
                await _db.SaveChangesAsync();
                return;
            }

        } // UpdateAsync
        } // ReadAll


        public async Task<MealItem> CreateAsync( Guid mealEntryId, MealItem mealItem )
        {
            var mealEntry = await _db.MealEntries
                .Include( o => o.MealItems )
                .SingleOrDefaultAsync( o => o.Id == mealEntryId );
            if ( mealEntry != null )
            {
                mealEntry.MealItems.Add( mealItem );    // Associate item with the entry
                mealItem.Meal = mealEntry;              // Associate the entry with the item
                await _db.SaveChangesAsync();

            }// End if mealEntry not null statement.

            if( Config.AuditingOn )
            {
                var auditChange = new AuditChange();
                auditChange.CreateAuditTrail( AuditActionType.CREATE, mealItem.Id.ToString(), new MealItem(), mealItem );
                await _auditRepo.CreateAsync( auditChange );

            } // if

            return mealItem;

        } // CreateAsync
        } // Create


        public async Task UpdateAsync( string username, Patient patient )
        {
            if( Exists( username ) )
            {
                var dbPatient = await ReadAsync( username );
                if( Config.AuditingOn )
                {
                    var auditChange = new AuditChange();
                    if( !auditChange.CreateAuditTrail( AuditActionType.UPDATE, patient.Id, dbPatient, patient ) )
                        await _auditRepo.CreateAsync( auditChange );

                } // if

                dbPatient.FirstName = patient.FirstName;
                dbPatient.LastName = patient.LastName;
                dbPatient.Address1 = patient.Address1;
                dbPatient.Address2 = patient.Address2;
                dbPatient.City = patient.City;
                dbPatient.State = patient.State;
                dbPatient.Zip1 = patient.Zip1;
                dbPatient.Zip2 = patient.Zip2;
                if( !String.IsNullOrEmpty( patient.PhoneNumber ) )
                    dbPatient.PhoneNumber = patient.PhoneNumber;
                if( !String.IsNullOrEmpty( patient.Email ) )
                    dbPatient.Email = patient.Email;
                if( patient.CreatedAt != null )
                    dbPatient.CreatedAt = patient.CreatedAt;
                dbPatient.UpdatedAt = DateTime.Now;
                if( !String.IsNullOrEmpty( patient.RemoteLoginToken.ToString() ) )
                    dbPatient.RemoteLoginToken = patient.RemoteLoginToken; // In case it has changed
                if( patient.Height > 0 )
                    dbPatient.Height = patient.Height;
                if( patient.Weight > 0 )
                    dbPatient.Weight = patient.Weight;
                if( patient.PatientSignedHIPAANotice != null )
                    dbPatient.PatientSignedHIPAANotice = patient.PatientSignedHIPAANotice;

                _db.Entry( dbPatient.Doctor ).State = EntityState.Detached;
                //_db.Attach( dbPatient.Doctor );
                //_db.Entry( dbPatient.Doctor ).Property( "Id" ).CurrentValue = patient.Doctor.Id;

                //if ( patient.Doctor != null )
                //{
                //    //dbPatient.DoctorUserName = patient.DoctorUserName;
                //    dbPatient.Doctor = patient.Doctor;
                //    _db.Entry( dbPatient.Doctor ).State = EntityState.Unchanged;
                //}

                //if ( dbPatient?.Doctor?.UserName == patient?.Doctor?.UserName )
                //{
                //}
                //else
                //{
                //    //if( !string.IsNullOrEmpty( patient.DoctorId ) && oldPatient.DoctorId != patient.DoctorId )
                //    //    oldPatient.DoctorId = patient.DoctorId;
                //    //if( !string.IsNullOrEmpty( patient.DrUserName ) && dbPatient.DrUserName != patient.DrUserName )
                //    //    dbPatient.DrUserName = patient.DrUserName;
                //    //if( patient.Doctor != null )
                //    //dbPatient.Doctor = patient.Doctor;
                //}

                _db.Entry( dbPatient ).State = EntityState.Modified;
                await _db.SaveChangesAsync();
            }
            return;

        } // UpdateAsync