Exemplo n.º 1
0
        public async Task <IActionResult> Create([FromBody] RoleViewModel role)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var dbRole = new ApplicationRole()
            {
                Name = role.Name
            };

            var identityResult = await _roleManager.CreateAsync(dbRole);

            if (!identityResult.Succeeded)
            {
                return(BadRequest(identityResult.Errors));
            }

            return(Ok(dbRole.ToViewModel()));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Update([FromRoute] int roleId, [FromBody] RoleViewModel role)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var dbRole = new ApplicationRole()
            {
                Id               = roleId,
                Name             = role.Name,
                ConcurrencyStamp = role.ConcurrencyStamp
            };

            var identityResult = await _roleManager.UpdateAsync(dbRole);

            if (!identityResult.Succeeded)
            {
                return(BadRequest(identityResult.Errors));
            }

            return(Ok(dbRole.ToViewModel()));
        }