public async Task <IActionResult> UpdateUserMemberships(IList <UserMembershipViewModel> model, string userId) { try { // TO DO: validate that the logged-in user is this user (ie: userId) or is a site admin. var addMemberships = new List <UserGroupMembership>(); var removeMemberships = new List <UserGroupMembership>(); foreach (UserMembershipViewModel item in model) { var membership = new UserGroupMembership() { UserId = userId, UserGroupId = item.UserGroupId, AllowEmailMessaging = item.AllowEmailMessaging, AllowSmsMessaging = item.AllowSmsMessaging, AccessLevel = Identity.Models.AccessLevel.Audience }; if (item.IsMember || item.AllowEmailMessaging || item.AllowSmsMessaging) { addMemberships.Add(membership); } else { removeMemberships.Add(membership); } } await _userGroupManager.UpdateGroupMemberships(userId, addMemberships, removeMemberships); return(Ok(model)); } catch (Exception ex) { Logger.LogError(ex.Message); return(BadRequest()); } }