public async Task <ActionResult> SaveUserGroupMembership(UserGroupMembershipViewModel model) { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(model.UserId); if (user == null) { ModelState.AddModelError("UserId", "Invalid UserId:" + model.UserId); return(BadRequest(ModelState)); } var member = model.ProjectTo <Angelo.Connect.Models.UserGroupMembership>(); await _userGroupManager.SaveUserGroupMembershipAsync(member); model.UserName = user.UserName; model.AccessLevelName = _enumLocalizer.GetLocalName(model.AccessLevel); return(Ok(model)); } return(BadRequest(ModelState)); }