コード例 #1
0
        public async Task <IActionResult> AddRole(RoleForAddDto roleForAddDto)
        {
            if (await _repo.RoleExists(roleForAddDto.RoleName))
            {
                return(BadRequest("Role Name already exists"));
            }

            var roleToAdd = _mapper.Map <Role>(roleForAddDto);

            var createdRole = await _repo.AddRole(roleToAdd);

            var roleToReturn = _mapper.Map <RoleForListDto>(createdRole);

            return(CreatedAtRoute("GetRole", new { controller = "Roles", id = createdRole.Id }, roleToReturn));
        }