I have extended the Member in BackOffice to have a Nested Content object on it called badges. Basically a logged in user can do things on the website to unlock/earn badges.
I have an UmbracoAPIController handling the call from the front end which looks as shown
[System.Web.Http.HttpGet]
public IContent IsNewBadge(int newSteps)
{
var contentService = ApplicationContext.Services.ContentService;
var memberService = ApplicationContext.Current.Services.MemberService;
// all available badges
var allBadges = contentService.GetById(1144).Children();
var secMember = Membership.GetUser();
if (secMember != null)
{
var currentMember = memberService.GetByUsername(secMember.UserName);
// Get all badges this member currently has - or return a new empty list if null
var allMemberBadges = currentMember.GetValue<List<IContent>>("badges") ?? new List<IContent>();
foreach (var badge in allBadges)
{
// check if the passed in number meets or exceeds a badge's required number
if (newSteps >= badge.GetValue<int>("badgeStepsRequired"))
{
// if the badge is not already in the list
if (!allMemberBadges.Contains(badge))
{
allMemberBadges.Add(badge);
currentMember.SetValue("badges", new List<IContent>(allMemberBadges));
memberService.Save(currentMember);
return badge;
}
}
}
}
return null;
}
My question is specifically around the "SetValue" method. Is this even the correct method that I should be using? It seems to only want (string,string) or (string,filestream).
The error that I get is
"Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'The best overloaded method match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' has some invalid arguments'"
"The best overloaded method match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' has some invalid arguments"
How can I update my custom member property via API?
Save object to Member via MemberService
Hey Everyone,
I have extended the Member in BackOffice to have a Nested Content object on it called badges. Basically a logged in user can do things on the website to unlock/earn badges. I have an UmbracoAPIController handling the call from the front end which looks as shown
My question is specifically around the "SetValue" method. Is this even the correct method that I should be using? It seems to only want (string,string) or (string,filestream).
The error that I get is
"Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'The best overloaded method match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' has some invalid arguments'"
"The best overloaded method match for 'Umbraco.Core.Models.ContentBase.SetPropertyValue(string, string)' has some invalid arguments"
How can I update my custom member property via API?
Thanks for any suggestions! -Roger
Hi Roger
Yes, this is the right method - "SetValue"
I think in this row you need to convert List to string, serialize the list to JSON for example.
Thanks,
Alex
is working on a reply...