public async Task <Unit> Handle(GrantAccessCommand request, CancellationToken cancellationToken)
        {
            if (!request.IsValid())
            {
                throw new MissingInformationProvidedException("invalid user details provided");
            }

            var user = userRepository.Get(request.UserId);

            if (user == null)
            {
                throw new UserDoesNotExistException($"no gate with id {request.UserId}");
            }


            if (gateRepository.Get(request.GateId) == null)
            {
                throw new GateDoesNotExistException($"no gate with id {request.GateId}");
            }

            user.GrantAccess(request.GateId);

            userRepository.Save(user);

            var accessGrantedEvent = new AccessGrantedEvent(request.UserId, request.GateId);
            await mediator.Publish(accessGrantedEvent, cancellationToken);

            return(Unit.Value);
        }
示例#2
0
 public void SaveAccessKey()
 {
     if (!HasAccessKey())
     {
         var key = Guid.NewGuid().ToString().Replace("-", "");
         _rootKey.SetValue(ACCESS_VALUE_NAME, key);
         WriteLine("Access key saved");
         AccessGrantedEvent?.Invoke(this, EventArgs.Empty);
     }
 }