private MemberProfile CopyMemberProfileToVm(cm.MemberProfile mp) { var mCopyDepot = new MemberFactory(); var addyCopyDepot = new AddressInfoFactory(); var mpVm = mCopyDepot.CreateMemberProfile <MemberProfile>(mp); foreach (var addy in mp.AddressList) { mpVm.AddressList.Add(addyCopyDepot.CreateAddress <AddressVm>(addy)); } foreach (var addy in mp.PhoneList) { mpVm.PhoneList.Add(addyCopyDepot.CreatePhone <PhoneVm>(addy)); } foreach (var addy in mp.EmailList) { mpVm.EmailList.Add(addyCopyDepot.CreateEmail <EmailVm>(addy)); } foreach (var attr in mp.CustomAttributeList) { mpVm.CustomAttributeList.Add(attr); } //foreach (var meta in mp.MetaDataList) // mpVm.MetaDataList.Add(meta); return(mpVm); }
//[ValidateAntiForgeryToken] //[VerifySessionAttribute] public async Task <ActionResult> SaveProfile(MemberProfile memberProfile) { InitSession(); var mFactory = new MemberFactory(); var addyFactory = new AddressInfoFactory(); var mp = mFactory.CreateMemberProfile <cm.MemberProfile>(memberProfile); foreach (var addy in memberProfile.AddressList) { var a = addyFactory.CreateAddress <Address>(addy); a.ModifiedByIdentityId = _session.UserId; mp.AddressList.Add(a); } foreach (var addy in memberProfile.PhoneList) { var p = addyFactory.CreatePhone <Phone>(addy); p.ModifiedByIdentityId = _session.UserId; mp.PhoneList.Add(p); } foreach (var addy in memberProfile.EmailList) { var e = addyFactory.CreateEmail <Email>(addy); e.ModifiedByIdentityId = _session.UserId; mp.EmailList.Add(e); } var json = await _apiProvider.PutItemAsync <cm.MemberProfile>($"{_uri}/{ memberProfile.MemberId}", mp); try { var m = _apiProvider.DeserializeJson <cm.MemberProfile>(json); if (m != null) { // reload page, so that any new id's can be loaded. return(RedirectToAction("Edit", new { id = m.MemberId })); } return(Content("Error saving profile")); } catch (Exception ex) { return(Content("Error saving profile: " + ex.Message)); } }