Skip to content

Commit ca5c573

Browse files
committed
#7 FetchUserProperty method for getting a KVP value
1 parent a935984 commit ca5c573

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/cloudscribe.UserProperties.Kvp/UserPropertyService.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System;
1313
using System.Collections.Generic;
1414
using System.Linq;
15+
using System.Security.Claims;
1516
using System.Threading.Tasks;
1617

1718
namespace cloudscribe.UserProperties.Kvp
@@ -24,7 +25,7 @@ IKvpStorageService kvpStorage
2425
)
2526
{
2627
_userManager = userManager;
27-
_kvpStorage = kvpStorage;
28+
_kvpStorage = kvpStorage;
2829
}
2930

3031
private SiteUserManager<SiteUser> _userManager;
@@ -177,6 +178,30 @@ public async Task<List<UserProperty>> FetchByUser(string siteId, string userId)
177178
return result;
178179
}
179180

181+
public async Task<string> FetchUserProperty(string userId, string key)
182+
{
183+
var result = (string)null;
184+
185+
if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(key))
186+
return result;
187+
188+
var siteUser = await _userManager.FindByIdAsync(userId);
189+
var siteId = siteUser?.SiteId.ToString();
190+
191+
if (!string.IsNullOrEmpty(siteId))
192+
{
193+
var kvpList = await _kvpStorage.FetchById(
194+
siteId, // projectId
195+
"*", // featureId
196+
siteId, // setId
197+
userId // subSetId
198+
).ConfigureAwait(false);
199+
200+
result = kvpList.FirstOrDefault(x => x.Key.Equals(key, StringComparison.OrdinalIgnoreCase))?.Value;
201+
}
202+
return result;
203+
}
204+
180205
public async Task CreateOrUpdate(string siteId, string userId, string key, string value)
181206
{
182207
if (string.IsNullOrWhiteSpace(siteId)) throw new ArgumentException("siteid must be provided");

src/cloudscribe.UserProperties.Kvp/cloudscribe.UserProperties.Kvp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>Configurable custom user properties for cloudscribe core using per tenant or global configuration based custom proprties with key/value storage</Description>
5-
<Version>4.1.2</Version>
5+
<Version>4.1.4</Version>
66
<Authors>Joe Audette</Authors>
77
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
88
<PackageTags>cloudscribe;userprofile;customization</PackageTags>

src/cloudscribe.UserProperties/Models/IUserPropertyService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using cloudscribe.Core.Models;
22
using System.Collections.Generic;
3+
using System.Security.Claims;
34
using System.Threading.Tasks;
45

56
namespace cloudscribe.UserProperties.Models
@@ -12,6 +13,7 @@ public interface IUserPropertyService
1213
string GetNativeUserProperty(ISiteUser siteUser, string key);
1314
void UpdateNativeUserProperty(ISiteUser siteUser, string key, string value);
1415
Task<List<UserProperty>> FetchByUser(string siteId, string userId);
16+
Task<string> FetchUserProperty(string userId, string key);
1517
Task CreateOrUpdate(string siteId, string userId, string key, string value);
1618
}
1719
}

src/cloudscribe.UserProperties/cloudscribe.UserProperties.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>Models for custom user properties that can be configured per tenant for cloudscribe core customization</Description>
5-
<Version>4.1.2</Version>
5+
<Version>4.1.4</Version>
66
<Authors>Joe Audette</Authors>
77
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
88
<PackageTags>cloudscribe;userprofile;customization</PackageTags>

0 commit comments

Comments
 (0)