@{
var m = new Member(Convert.ToInt32(System.Web.Security.Membership.GetUser().ProviderUserKey));
var local = m.getProperty("PhoneLocal").Value.ToString();
var nLocal = Request.QueryString["local"];
if(!String.IsNullOrEmpty(@nLocal))
{
if(@nLocal != @local)
{
m.getProperty("PhoneLocal").Value = @nLocal;
}
}
}
You'll probably want to use the new Member Service to update a member property:
// Find the current member
var username = System.Web.Security.Membership.GetUser().UserName;
var member = Umbraco.Core.ApplicationContext.Services.MemberService.GetByUsername(username);
// Update the member
member.SetValue("alias", "value");
// Save the member
Umbraco.Core.ApplicationContext.Services.MemberService.Save(member);
Thank you! It probably works, but i get this error:
An object reference is required for the non-static field, method, or property 'Umbraco.Core.ApplicationContext.Services.get
What reference am I missing?
Is there an easier way of retrieving member properties, that the one I use above? Do you have a link for some documentation on the new member service? :-)
You can find more information on the Member Service here.
Where are trying to update the member? On a template or within a controller for example? Secondly, does the property exist on the member type you are trying to update and is the alias PhoneLocal correct?
Hmmm strange. Come to think of it, you shouldn't need the using statements as mentioned above. Also, try changing your service namespace references to something like the following. I've also added an extra check to see if the current member can be found:
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
// Find the current member
var membershipUser = Membership.GetUser();
if (membershipUser != null)
{
var membershipUsername = membershipUser.UserName;
var member = ApplicationContext.Services.MemberService.GetByUsername(membershipUsername);
// Update the member
member.SetValue("PhoneLocal", "0123456789");
// Save the member
ApplicationContext.Services.MemberService.Save(member);
}
}
Have you created the script as a Macro Script (~/MacroScripts) or a Partial View Macro (~/Views/MacroPartials)? If its the former, then you will want to create it is a Partial View Macro instead and use that with your macro.
Set member property u7
Hi
So I want to give a member property a new value and I had it working in u4, but it is not working in u7. What changed?
Original thread
Thank you for the help!
/Daniel
Hi Daniel,
You'll probably want to use the new Member Service to update a member property:
Thanks, Dan.
Thank you! It probably works, but i get this error:
An object reference is required for the non-static field, method, or property 'Umbraco.Core.ApplicationContext.Services.get
What reference am I missing?
Is there an easier way of retrieving member properties, that the one I use above? Do you have a link for some documentation on the new member service? :-)
/Daniel
Hi Daniel,
You can find more information on the Member Service here.
Where are trying to update the member? On a template or within a controller for example? Secondly, does the property exist on the member type you are trying to update and is the alias PhoneLocal correct?
Thanks, Dan.
I am making a macroscript with this code. The property does exist on that membertype.
I added this, but stiil get the error:
@using Umbraco.Core;
@using Umbraco.Core.Models;
@using Umbraco.Core.Services;
Is it right or am I doing it wrong?
/Daniel
Hmmm strange. Come to think of it, you shouldn't need the using statements as mentioned above. Also, try changing your service namespace references to something like the following. I've also added an extra check to see if the current member can be found:
Thanks, Dan.
Now i get this error message: Context Must Implement System.Web.WebPages.WebPage
/Daniel
Have you created the script as a Macro Script (~/MacroScripts) or a Partial View Macro (~/Views/MacroPartials)? If its the former, then you will want to create it is a Partial View Macro instead and use that with your macro.
Thanks, Dan.
Thank you, it works! I made a partial view and that did the trick :-)
/Daniel
is working on a reply...