Edit Associated Profile Entities
Abstract
Create a page using addresses within an MVC site.
Complete the following prerequisites:
Integrate Profile Properties with the Sitecore Profile Store
You have setup a page in Sitecore with associated codebehind or MVC Controller.
At your Visual Studio Solution setup:
Get all user addresses
List<MVCSite.Models.Generated.Address> models = null; if (Sitecore.Context.User.IsAuthenticated) { var user = Sitecore.Context.User; var commerceProfile = user.GetCommerceProfileModel(); if (commerceProfile.AddressList != null) { models = Address.GetMultiple(commerceProfile.AddressList); } } return View(models);
Create or edit an address.
if (model != null && Sitecore.Context.User.IsAuthenticated) { var user = Sitecore.Context.User; var profileModel = user.GetCommerceProfileModel(); if (string.IsNullOrEmpty(model.AddressID)) { var address = Address.Create(); model.Save(address); profileModel.AddressList.Add(model.AddressID); profileModel.AddressList = profileModel.AddressList; profileModel.Save(); } else { if (profileModel.AddressList.Contains(model.AddressID)) { var address = Address.GetCommerceProfile(model.AddressID); if (address != null) { model.Save(address); } } } }