public async Task SetPolicy(GroupPolicyDto policy, Guid groupId) { foreach (var email in policy.Emails) { // get user data var user = await _userManager.FindByEmailAsync(email); if (user == null) { user = await _appUserService.AddUserByEmailWithoutPassword(email); } foreach (var role in policy.Roles) { await _userManager.AddToRoleAsync(user, role, groupId); } using (var uow = _uowProvider.CreateUnitOfWork()) { var repository = uow.GetRepository <MemberGroups>(); await repository.AddAsync(new MemberGroups() { UserId = user.Id, GroupId = groupId }); await uow.SaveChangesAsync(); } } }
//[Authorize(Policy = SystemStaticPermissions.Groups.SetIamPolicy)] public async Task <IActionResult> SetIamPolicy([FromBody] GroupPolicyDto model) { //var _userId = this.HttpContext.User.Claims.First(c => c.Type == "sub").Value; var groupId = model.GroupId; await _groupMemberService.SetPolicy(model, groupId); return(Ok()); }