Example #1
0
        public async Task AddClaimAsync(long userId, TbaUserClaim claim)
        {
            var user = await FindByIdAsync(userId);

            if (user == null)
            {
                throw new Exception("User does not exist");
            }
            user.Claims.Add(claim);
            await _db.SaveChangesAsync();
        }
Example #2
0
        public async Task <Unit> Handle(DeleteUserCommand request, CancellationToken cancellationToken)
        {
            var user = await _usersDbContext.Users.FirstOrDefaultAsync(x => x.UserId == request.UserId);

            if (user == null)
            {
                throw new NotFoundException(ErrorMessages.UserNotFoundErrorMessage);
            }

            _usersDbContext.Users.Remove(user);
            await _usersDbContext.SaveChangesAsync();

            return(Unit.Value);
        }
        public async Task <Unit> Handle(UpdateUserCommand request, CancellationToken cancellationToken)
        {
            var user = await _usersDbContext.Users.FirstOrDefaultAsync(x => x.UserId == request.UserId);

            if (user == null)
            {
                throw new NotFoundException(ErrorMessages.UserNotFoundErrorMessage);
            }

            user.FirstName    = request.FirstName;
            user.LastName     = request.LastName;
            user.EmailAddress = request.EmailAddress;
            user.DOB          = request.DOB;

            await _usersDbContext.SaveChangesAsync();

            return(Unit.Value);
        }
Example #4
0
        public async Task <Guid> Handle(CreateUserCommand request, CancellationToken cancellationToken)
        {
            var user = new User
            {
                UserId       = Guid.NewGuid(),
                FirstName    = request.FirstName,
                LastName     = request.LastName,
                EmailAddress = request.EmailAddress,
                DOB          = request.DOB,
                Active       = true,
                CreatedDate  = DateTime.Now
            };

            await _usersDbContext.Users.AddAsync(user);

            await _usersDbContext.SaveChangesAsync();

            await _mediator.Publish(new UserCreatedNotification(user.UserId));

            return(user.UserId);
        }