Update user's email in Orchard

Topics: Core, Customizing Orchard
Jun 6, 2013 at 9:21 AM
I want to allow users to update their email, so I have controller :
[HttpPost]
public ActionResult ChangeEmail(string newEmail) {
    IUser user = _services.WorkContext.CurrentUser;
    if (!user.Is<UserPart>())
        throw new InvalidCastException();

    var userRecord = user.As<UserPart>().Record;
    userRecord.Email = newEmail;
    return null;
}
Everything builds and runs OK except that the database doesn't update new email. What should I do ? Thanks all !
Developer
Jun 6, 2013 at 10:49 AM
Edited Jun 6, 2013 at 10:50 AM
try this..
[HttpPost]
public ActionResult ChangeEmail(string newEmail) {
    IUser user = _contentManager.Get(_services.WorkContext.CurrentUser.Id).As<IUser>();
    user.Email = newEmail;
    return new EmptyResult();
}
Jun 6, 2013 at 1:10 PM
Jetski5822 wrote:
try this..
[HttpPost]
public ActionResult ChangeEmail(string newEmail) {
    IUser user = _contentManager.Get(_services.WorkContext.CurrentUser.Id).As<IUser>();
    user.Email = newEmail;
    return new EmptyResult();
}
That was my awkward mistake. The newEmail parameter was wrong. The code in my Controller was absolutely right.
Thanks so much Jetski5822
Developer
Jun 9, 2013 at 10:34 PM
no problem.