Ejemplo n.º 1
0
        public async Task <IActionResult> UpdateRole(int id, RoleForUpdateDto roleForUpdateDto)
        {
            var roleFromRepo = await _repo.GetRole(id);

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

            _mapper.Map(roleForUpdateDto, roleFromRepo);

            if (await _repo.SaveAll())
            {
                return(NoContent());
            }

            throw new Exception($"Updating Role {id} failed on save");
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> UpdateRole(string id, RoleForUpdateDto roleForUpdateDto)
        {
            var roleFromRepo = await _roleManager.FindByIdAsync(id);

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

            _mapper.Map <RoleForUpdateDto, AppRole>(roleForUpdateDto, roleFromRepo);

            var result = await _roleManager.UpdateAsync(roleFromRepo);

            if (!result.Succeeded)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }

            return(NoContent());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UpdateRole(string id, [FromBody] RoleForUpdateDto roleForUpdateDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var role = await _auth.GetRole(id);

            if (role == null)
            {
                return(NotFound($"Could not found role with an ID of {id}"));
            }
            role.Name           = roleForUpdateDto.Name;
            role.NormalizedName = roleForUpdateDto.Name;
            var res = await _roleManager.UpdateAsync(role);

            if (res.Succeeded)
            {
                return(NoContent());
            }
            throw new Exception($"Updating role {id} failed on save");
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> UpdateRole(string id, [FromBody] RoleForUpdateDto role)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var roleExists = await _roleManager.FindByIdAsync(id);

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

            var roleEntity = _mapper.MapToInstance(role, roleExists);
            var result     = await _roleManager.UpdateAsync(roleEntity);

            if (!result.Succeeded)
            {
                throw new Exception($"Update role {id} failed on save.");
            }

            return(NoContent());
        }