Esempio n. 1
0
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member 'AccountController.GetRoles()'
        public async Task <ActionResult <ResultAccountGetRoles> > GetRoles()
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member 'AccountController.GetRoles()'
        {
            ResultAccountGetRoles res;

            try
            {
                //var user = _userManager.FindByEmailAsync(email).Result;
                var user = await _signInManager.UserManager.GetUserAsync(User);

                if (user.EmailConfirmed)
                {
                    await SeedData.EnsureRole(Program.MyHost.Services, user.Id, Authorizarion.Constants.UserRoleConfirmed, _roleManager, _userManager);
                }
                var roles = await _userManager.GetRolesAsync(user);

                var list = await _context.Roles.Select(a => a.Name).ToListAsync();

                res = new ResultAccountGetRoles(roles, list);

                return(Ok(res));
            }
            catch (Exception e)
            {
                res = new ResultAccountGetRoles(e);
                return(BadRequest(res));
            }
        }
Esempio n. 2
0
        public async Task <ActionResult <ResultAccountGetRoles> > GetRoles()
        {
            ResultAccountGetRoles res;

            try
            {
                //var user = _userManager.FindByEmailAsync(email).Result;
                var user = await _signInManager.UserManager.GetUserAsync(User);

                if (user.EmailConfirmed)
                {
                    await SeedData.EnsureRole(Program.MyHost.Services, user.Id, API.Authorizarion.Constants.UserRoleConfirmed, _roleManager, _userManager);
                }
                var roles = await _userManager.GetRolesAsync(user);

                var possibleRoles = await _context.Roles.ToListAsync();

                var list = (from a in possibleRoles select a.Name).ToList();
                res = new ResultAccountGetRoles(roles, list);

                return(Ok(res));
            }
            catch (Exception e)
            {
                res = new ResultAccountGetRoles(e);
                return(BadRequest(res));
            }
        }