Example #1
0
        public async Task <ApiResult <RoleForDto> > UpdateRole(RoleForDto roleDto)
        {
            using (_log.BeginScope())
            {
                _log.Write($"Update role {roleDto.Name}");

                var role = _mapper.Map <RoleForDto, Role>(roleDto);

                // check if there are user with this role before delete
                // if there is send message that role can't be deleted
                if (!roleDto.Active)
                {
                    if (await _roleBus.IsSafeToDeleteRole(role))
                    {
                        return(ApiResult <RoleForDto> .Forbidden("There are active users with this role. Please remove all users to delete role."));
                    }
                }

                await _roleBus.UpdateRole(role);

                _log.Write($"Successfully update role id {role.Id}");

                var roleDtoReturn = _mapper.Map <Role, RoleForDto>(role);

                return(ApiResult <RoleForDto> .Created(roleDtoReturn));
            }
        }
Example #2
0
        public async Task <ApiResult <RoleForDto> > AddRole(RoleForDto roleDto)
        {
            using (_log.BeginScope())
            {
                _log.Write($"Adding new role {roleDto.Name}");

                var role = _mapper.Map <RoleForDto, Role>(roleDto);

                await _roleBus.AddRole(role);

                _log.Write($"Successfully added new role id {role.Id}");

                var roleDtoReturn = _mapper.Map <Role, RoleForDto>(role);

                return(ApiResult <RoleForDto> .Created(roleDtoReturn));
            }
        }