Exemplo n.º 1
0
        public async Task <Response> Execute(Request request)
        {
            request.Treatment();

            Validate(request);

            var user = await _usersRepository.GetByCpf(request.Cpf);

            if (user != null)
            {
                _notifications.Add($"Já existe um usuário com o CPF {request.Cpf}.", nameof(Request.Cpf));
            }

            if (!_notifications.IsValid())
            {
                return(new Response()
                {
                    Errors = _notifications.Notifications
                });
            }

            user = request.ToUser();

            await _usersRepository.Add(user);

            var token = await _tokenService.GenerateToken(user);

            return(new Response()
            {
                User = UserDto.From(user),
                Token = token,
                Errors = _notifications.Notifications
            });
        }
Exemplo n.º 2
0
        public async Task <ActionResult <List <UserDto> > > GetAllUsersAsync()
        {
            Guid?appUserId = null;
            var  claims    = User.Claims.Where(s => s.Type == "role").Select(s => s.Value).ToList();
            var  canAdminisiterAllUsers = claims.Any(o => o.ToLower() == Constaints.ClaimAdminisiterAllUsers.ToLower());

            if (!canAdminisiterAllUsers)
            {
                appUserId = this.AppUserId;
            }
            var data = await _userRepository.GetAppUsersWithChildrenAsync(appUserId);

            return(data.Select(o => UserDto.From(o)).OrderBy(o => o.LastName).ToList());
        }