Beispiel #1
0
        //editDbUserHelperAsync - single record
        private async Task editDbUserHelperAsync(DBUser record)
        {
            if (record.LDAPAuthenticated_bl)
            { record.Password = Guid.NewGuid().ToString(); record.PasswordConf = record.Password; }

            var dbEntry = await appUserManager.FindByIdAsync(record.Id).ConfigureAwait(false);
            if (dbEntry == null)
            {
                var createResult = await appUserManager.CreateAsync(record, record.Password).ConfigureAwait(false);
                if (!createResult.Succeeded)
                {
                    throw new DbBadRequestException(
                        String.Format("Error creating user {0}:{1}\n", record.UserName, getErrorsFromIdResult(createResult)));
                }
            }
            else
            {
                if (record.PropIsModified(x => x.UserName)) dbEntry.UserName = record.UserName;
                if (record.PropIsModified(x => x.Email)) dbEntry.Email = record.Email;
                if (record.PropIsModified(x => x.LDAPAuthenticated_bl)) dbEntry.LDAPAuthenticated_bl = record.LDAPAuthenticated_bl;
                if (record.PropIsModified(x => x.Password)) dbEntry.PasswordHash = appUserManager.HashPassword(record.Password);
                var updateResult = await appUserManager.UpdateAsync(dbEntry).ConfigureAwait(false);
                if (!updateResult.Succeeded)
                {
                    throw new DbBadRequestException(
                        String.Format("Error editing user {0}:{1}\n", record.UserName, getErrorsFromIdResult(updateResult)));
                }
            }
        }
Beispiel #2
0
        //Helpers--------------------------------------------------------------------------------------------------------------//
        #region Helpers

        //checkDbUserBeforeEditHelperAsync - single record
        private void checkDbUserBeforeEditHelper(DBUser record)
        {
            if (record.PropIsModified(x => x.LDAPAuthenticated_bl) && !record.LDAPAuthenticated_bl && String.IsNullOrEmpty(record.Password))
            {
                throw new DbBadRequestException(
                    String.Format("User {0}: Password is required if not LDAP authenticated\n", record.UserName));
            }
        }