使用自定义成员模型扩展Umbraco ProfileModel

时间:2015-11-26 13:57:38

标签: asp.net-membership umbraco umbraco7

我在更新会员帐户详细信息时有以下代码:

/// <summary>
/// Verifies and edits the member fields.
/// </summary>
/// <param name="model"></param>
/// <returns>MemberDetailsFormViewModel containing all the editable information.</returns>
[Authorize]
public ActionResult HandleUpdateMemberDetails(MemberDetailsFormViewModel model)
    {
        if (ModelState.IsValid == false)
        {
            return CurrentUmbracoPage();
        }

        var memberService = Services.MemberService;
        var member = memberService.GetById(Members.GetCurrentMemberId());

        member.Properties[Constant.PropertyAlias.Authentication.FirstName].Value    = model.FirstName;
        member.Properties[Constant.PropertyAlias.Authentication.LastName].Value     = model.LastName;
        member.Properties[Constant.PropertyAlias.Authentication.AddressLine1].Value = model.AddressLine1;
        member.Properties[Constant.PropertyAlias.Authentication.AddressLine2].Value = model.AddressLine2;
        member.Properties[Constant.PropertyAlias.Authentication.TownCity].Value     = model.TownCity;
        member.Properties[Constant.PropertyAlias.Authentication.PostCode].Value     = model.PostCode;
        member.Properties[Constant.PropertyAlias.Authentication.County].Value       = model.County;
        member.Properties[Constant.PropertyAlias.Authentication.Country].Value      = model.Country;
        member.Properties[Constant.PropertyAlias.Authentication.PhoneNumber].Value  = model.PhoneNumber;

        memberService.Save(member);

        if (Members.IsLoggedIn())
        {
            ViewBag.DetailSuccessfullyChanged = 1;
            return CurrentUmbracoPage();
        }

        return View("/");
}

虽然此解决方案有效,但我希望使用以下member.Properties["propertyName"].Value方法ProfileModel通过扩展MembershipHelper进行更多优雅更新UpdateMemberProfile(ProfileModel model):{{ 1}}。

有用的链接:

有没有人设法做过这样的事情?

修改

我看到Warren在他的GitHub上做了Similar issue on OUR Umbraco

0 个答案:

没有答案