Esempio n. 1
0
        public async Task <ActionResult <IEnumerable <UserDto> > > GetUsers()
        {
            var allUsersFromRepo = await _userRepository.GetUsers();

            var client = await MicrosoftGraphClient.GetGraphServiceClient();

            var allUsersFromAzureAd = await _azureAdRepository.GetUsers(client);

            var mergedUsers = DataMerger.MergeUsersWithAzureData(allUsersFromRepo,
                                                                 allUsersFromAzureAd, _mapper);

            return(Ok(mergedUsers));
        }
        public async Task <ActionResult <IEnumerable <UserDto> > > GetSmartLockUsers(Guid smartLockId)
        {
            var smartLockExists = await _smartLockRepository.SmartLockExists(smartLockId);

            if (!smartLockExists)
            {
                return(NotFound());
            }

            var allSmartLockUsersFromRepo = await _smartLockRepository.GetSmartLockUsers(smartLockId);

            var client = await MicrosoftGraphClient.GetGraphServiceClient();

            var allUsersFromAzureAd = await _azureAdRepository.GetUsers(client);

            var mergedSmartLockUsers = DataMerger.MergeUsersWithAzureData(
                allSmartLockUsersFromRepo, allUsersFromAzureAd, _mapper);

            return(Ok(mergedSmartLockUsers));
        }
Esempio n. 3
0
        public async Task <IEnumerable <AdminAccessDto> > GetAccesses()
        {
            var allAccessesFromRepo = await _accessRepository.GetAccesses();

            var client = await MicrosoftGraphClient.GetGraphServiceClient();

            var allUsersFromAzureAd = await _azureAdRepository.GetUsers(client);

            var allSmartLocks = await _smartLockRepository.GetSmartLocks();

            var logsFromRepo = allAccessesFromRepo.ToList();

            var mergedUsers = (from logFromRepo in logsFromRepo
                               from dbUserFromAzureAd in allUsersFromAzureAd
                               where logFromRepo.UserId == Guid.Parse(dbUserFromAzureAd.Id)
                               let dtoFromDb = _mapper.Map <AdminAccessDto>(logFromRepo)
                                               select _mapper.Map(dbUserFromAzureAd, dtoFromDb))
                              .OrderByDescending(al => al.Time).ToList();

            var mergedSmartLocks = (from logFromRepo in logsFromRepo
                                    from smartLockFromRepo in allSmartLocks
                                    where logFromRepo.SmartLockId == smartLockFromRepo.Id
                                    let dtoFromDb = _mapper.Map <AdminAccessDto>(logFromRepo)
                                                    select _mapper.Map(smartLockFromRepo, dtoFromDb)).ToList();


            foreach (var ul in mergedUsers)
            {
                foreach (var sll in mergedSmartLocks)
                {
                    if (ul.SmartLockId == sll.SmartLockId)
                    {
                        ul.SmartLockTitle = sll.SmartLockTitle;
                    }
                }
            }

            return(mergedUsers);
        }
        public async Task <ActionResult <IEnumerable <AzureAdUserDto> > > GetUsers()
        {
            var users = new List <UserDto>();

            try
            {
                // Initialize the GraphServiceClient.
                var client = await MicrosoftGraphClient.GetGraphServiceClient();

                // Load users profiles.
                var userList = await _azureAdRepository.GetUsers(client);

                var userListDto = _mapper.Map <IEnumerable <AzureAdUserDto> >(userList);
                foreach (var azureAdUserDto in userListDto)
                {
                    var userExist = await _userRepository.UserExists(azureAdUserDto.Id);

                    if (userExist)
                    {
                        azureAdUserDto.AddedToDb = true;
                    }
                }

                return(Ok(userListDto));
            }
            catch (ServiceException ex)
            {
                if (ex.StatusCode == HttpStatusCode.BadRequest)
                {
                    return(BadRequest());
                }
                else
                {
                    return(NotFound());
                }
            }
        }