Пример #1
0
        public async Task <IHttpActionResult> ChangeRoleName([FromUri] string id, [FromBody] RoleBindingModel roleModel)
        {
            if (roleModel == null)
            {
                return(BadRequest("Payload is empty!"));
            }

            var role = await RoleManager.FindByIdAsync(id);

            if (role == null)
            {
                return(NotFound());
            }

            role.Name = roleModel.Name;
            IdentityResult createRoleResult = await RoleManager.UpdateAsync(role);

            if (!createRoleResult.Succeeded)
            {
                return(GetErrorResult(createRoleResult));
            }

            var roleDto        = RoleFactory.GetModel <RoleForAdminDto>(role);
            Uri locationHeader = new Uri(Url.Link("GetRole", new { id = role.Id }));

            return(Created(locationHeader, roleDto));
        }
Пример #2
0
        public async Task <IHttpActionResult> GetRoleByName(string name)
        {
            var role = await RoleManager.FindByNameAsync(name);

            if (role == null)
            {
                return(NotFound());
            }

            var roleDto = RoleFactory.GetModel <RoleForAdminDto>(role);

            return(Ok(roleDto));
        }