public void AddUser(User user)
        {
            if (EmailAlreadyExists(user.Email))
                throw new EmailAlreadyExistsException();

            if(CpfAlreadyExists(user.Cpf))
                throw new CpfAlreadyExistsException();

            _userRepository.AddUser(user);
            _userRepository.Save();
        }
        public Guid GenerateAccessTokenForUser(User user)
        {
            AccessToken tokenDeleted = _accessTokenRepository.GetAccessTokenByUserId(user.UserId);
            if(tokenDeleted != null)
                _accessTokenRepository.DeleteAccessToken(tokenDeleted.AccessTokenId);

            AccessToken newToken = new AccessToken();
            newToken.AccessTokenId = Guid.NewGuid();
            newToken.UserId = user.UserId;

            _accessTokenRepository.AddAccessToken(newToken);

            _accessTokenRepository.Save();

            return newToken.AccessTokenId;
        }
Exemplo n.º 3
0
        public User MapToUser(UserViewModel model)
        {
            User user = new User
            {
                Name = model.Name,
                Cpf = model.Cpf,
                BirthDate = Convert.ToDateTime(model.BirthDate),
                Gender = model.Gender,
                State = model.State,
                City = model.City,
                Neighborhood = model.Neighborhood,
                Street = model.Street,
                Email = model.Email,
                Password = model.Password
            };

            return user;
        }
 public void AddUser(User user)
 {
     _context.Users.Add(user);
 }