private async Task <AdminUser> LoadSensitiveDataAsync(AdminUserEncrypted adminUserEncrypted) { var admin = new AdminUser { AdminUserId = adminUserEncrypted.AdminUserId, RegisteredAt = adminUserEncrypted.RegisteredAt, IsActive = adminUserEncrypted.IsActive, UseDefaultPermissions = adminUserEncrypted.UseDefaultPermissions }; var adminId = Guid.Parse(adminUserEncrypted.AdminUserId); var response = await _customerProfileClient.AdminProfiles.GetByIdAsync(adminId); if (response.ErrorCode != AdminProfileErrorCodes.None) { _log.Error(message: "An error occurred while getting admin profile.", context: $"adminUserId: {adminUserEncrypted.AdminUserId}; error: {response.ErrorCode}"); } else { admin.FirstName = response.Data.FirstName; admin.LastName = response.Data.LastName; admin.Email = response.Data.Email; admin.Company = response.Data.Company; admin.Department = response.Data.Department; admin.JobTitle = response.Data.JobTitle; admin.PhoneNumber = response.Data.PhoneNumber; } return(admin); }
private async Task <AdminUser> LoadSensitiveDataAsync(AdminUserEncrypted adminUserEncrypted) { var admin = _mapper.Map <AdminUser>(adminUserEncrypted); var adminId = Guid.Parse(adminUserEncrypted.AdminUserId); var adminProfile = await _customerProfileClient.AdminProfiles.GetByIdAsync(adminId); if (adminProfile.ErrorCode != AdminProfileErrorCodes.None) { _log.Error(message: "An error occurred while getting admin profile.", context: $"adminUserId: {adminUserEncrypted.AdminUserId}; error: {adminProfile.ErrorCode}"); } else { _mapper.Map(adminProfile.Data, admin); } return(admin); }
public async Task <bool> TryCreateAsync(AdminUserEncrypted adminUserEncrypted) { using (var context = _contextFactory.CreateDataContext()) { var entity = await context.AdminUser .FirstOrDefaultAsync(a => a.EmailHash == adminUserEncrypted.EmailHash); if (entity != null) { return(false); } entity = _mapper.Map <AdminUserEntity>(adminUserEncrypted); context.AdminUser.Add(entity); await context.SaveChangesAsync(); return(true); } }
public async Task <bool> TryUpdateAsync(AdminUserEncrypted adminUserEncrypted) { using (var context = _contextFactory.CreateDataContext()) { var entity = await context.AdminUser .AsNoTracking() .FirstOrDefaultAsync(a => a.AdminUserId == adminUserEncrypted.AdminUserId); if (entity == null) { return(false); } entity = _mapper.Map <AdminUserEntity>(adminUserEncrypted); context.AdminUser.Update(entity); await context.SaveChangesAsync(); return(true); } }