예제 #1
0
        public async Task <bool> AddRolesToUser(AddRolesToUserModelRq model)
        {
            try
            {
                var user = await _userManagement.FindByIdAsync(model.UserId.ToString());

                if (user == null)
                {
                    return(false);
                }
                foreach (var item in model.Roles)
                {
                    var rs = await _userManagement.AddToRoleAsync(user, item.Name);

                    if (!rs.Succeeded)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #2
0
 public async Task <IActionResult> AddRolesToUser([FromBody] AddRolesToUserModelRq models)
 {
     if (!ModelState.IsValid)
     {
         Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection modelErrors = new Microsoft.AspNetCore.Mvc.ModelBinding.ModelErrorCollection();
         foreach (var entry in ModelState.Values)
         {
             foreach (var error in entry.Errors)
             {
                 modelErrors.Add(error);
             }
         }
         return(BadRequest(modelErrors));
     }
     return(OkValueObject(await _userService.AddRolesToUser(models)));
 }