Пример #1
0
        public async Task <IActionResult> GetEmail()
        {
            var user = await _queryBuilder
                       .ForGeneric <User>()
                       .Where(UserSpecifications.WithId(_contextService.GetUserId()))
                       .FirstOrDefaultAsync();

            return(Ok(user.Email));
        }
        private User GetUserByUsername(string username)
        {
            User user = _userRepository.Find.One(UserSpecifications.Username(username));

            if (user == null)
            {
                throw new UserNotFoundException();
            }

            return(user);
        }
        private User GetUserByEmail(string email)
        {
            User user = _userRepository.Find.One(UserSpecifications.Email(email));

            if (user == null)
            {
                throw new UserNotFoundByEmailException();
            }

            return(user);
        }
Пример #4
0
        private async void HandleDial(Command command, RemoteUser remoteUser)
        {
            var callerNumber = _commandBuilder.GetUnderlyingObject <string>(command);
            var opponent     = _connectionsManager.FindRemoteUserByNumber(callerNumber);

            var dialResult = new DialResult();

            if (opponent == null)
            {
                var opponentUser = _usersRepository.FirstMatching(UserSpecifications.Number(callerNumber));
                if (opponentUser != null)
                {
                    _pushSender.SendVoipPush(opponentUser.PushUri, remoteUser.User.Number, remoteUser.User.Number);
                    var resultCommand = await _connectionsManager.PostWaiter(opponentUser.UserId, CommandName.IncomingCall);

                    var answerType = _commandBuilder.GetUnderlyingObject <AnswerResultType>(resultCommand);
                    if (answerType == AnswerResultType.Answered)
                    {
                        dialResult.Result       = DialResultType.Answered;
                        opponent.IsInCallWith   = remoteUser;
                        remoteUser.IsInCallWith = opponent;
                    }
                    else
                    {
                        dialResult.Result = DialResultType.Declined;
                    }
                }
                else
                {
                    dialResult.Result = DialResultType.NotFound;
                }
            }
            else
            {
                var incomingCallCommand = _commandBuilder.Create(CommandName.IncomingCall, callerNumber);
                var resultCommand       = await opponent.Peer.SendCommandAndWaitAnswer(incomingCallCommand);

                var answerType = _commandBuilder.GetUnderlyingObject <AnswerResultType>(resultCommand);
                if (answerType == AnswerResultType.Answered)
                {
                    dialResult.Result       = DialResultType.Answered;
                    opponent.IsInCallWith   = remoteUser;
                    remoteUser.IsInCallWith = opponent;
                }
                else
                {
                    dialResult.Result = DialResultType.Declined;
                }
            }
            _commandBuilder.ChangeUnderlyingObject(command, dialResult);
            remoteUser.Peer.SendCommand(command);
        }
Пример #5
0
        private void _resource_OnReceived(object sender, PeerCommandEventArgs e)
        {
            try
            {
                lock (_activeConnections)
                {
                    var command = _serializer.Deserialize(e.Data);
                    if (!string.IsNullOrEmpty(command.UserId))
                    {
                        lock (_responceWaiters)
                        {
                            TaskCompletionSource <Command> taskSource;
                            if (_responceWaiters.TryGetValue(new Tuple <string, CommandName>(command.UserId, command.Name),
                                                             out taskSource))
                            {
                                taskSource.TrySetResult(command);
                            }
                        }
                    }

                    var        user = _userRepository.FirstMatching(UserSpecifications.UserId(command.UserId));
                    RemoteUser remoteUser;
                    if (user != null)
                    {
                        var existedConnection = _activeConnections.FirstOrDefault(i => i.User.Equals(user));
                        if (existedConnection != null)
                        {
                            existedConnection.Peer = e.Peer;
                            existedConnection.Peer.HandleActivity();
                            remoteUser = existedConnection;
                        }
                        else
                        {
                            remoteUser = new RemoteUser(user, e.Peer);
                        }
                        _activeConnections.Add(remoteUser);
                    }
                    else
                    {
                        remoteUser = new RemoteUser(new User(), e.Peer);
                        _activeConnections.Add(remoteUser);
                    }
                    CommandRecieved(this, new RemoteUserCommandEventArgs {
                        Command = command, RemoteUser = remoteUser
                    });
                }
            }
            catch (Exception exc)
            {
                Logger.Exception(exc, "_resource_OnReceived");
            }
        }
Пример #6
0
        /// <summary>
        /// get user by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public UserDTO GetUserById(int id)
        {
            using (_queryableUnitOfWork)
            {
                // 1. Pass value to repository and use linq specifications
                //var user = _userRepository.GetUserById(1);

                // 2. create specifications in service and use
                var specification = UserSpecifications.UserIdEquals(id);

                var user2 = _userRepository.AllMatching(specification).FirstOrDefault();

                return(UserAdapter.AdaptToUserDto(user2));
            }
        }
        public IQueryable <User> GetUsers(string fullname)
        {
            IQueryable <User> query = _userRepository;

            if (!string.IsNullOrWhiteSpace(fullname))
            {
                query = query.GetFinder()
                        .All(UserSpecifications.FirstNameContains(fullname).Or(UserSpecifications.LastNameContains(fullname)))
                        .AsQueryable();
            }

            var users = query
                        .OrderBy(x => x.FirstName + x.LastName).AsQueryable();

            return(users);
        }
        public async Task <UserPaginationViewModel> GetByPage(
            UserFilters filters,
            int currentPage,
            int pageSize,
            string orderByPropertyName,
            bool isAsc)
        {
            var specifications = new UserSpecifications(filters.TrueName, filters.Gender, filters.IsEnabled);
            var users          = await _userRepository.GetAll().Where(specifications.Expression)
                                 .SortByProperty(orderByPropertyName, isAsc)
                                 .Skip(pageSize * (currentPage - 1))
                                 .Take(pageSize).ToListAsync();

            var total = _userRepository.GetAll().Where(specifications.Expression).Count();

            var results = users.Select(x => _mapper.Map <UserPageViewModel>(x)).ToList();

            return(new UserPaginationViewModel(results, currentPage, pageSize, total));
        }
Пример #9
0
        private async void HandleAuthentication(RemoteUser remoteUser, Command command)
        {
            var request = _commandBuilder.GetUnderlyingObject <AuthenticationRequest>(command);
            var result  = new AuthenticationResult();

            var user = _usersRepository.FirstMatching(UserSpecifications.UserId(request.UserId));

            if (user != null)
            {
                result.Result   = AuthenticationResultType.Success;
                user.OsName     = request.OsName;
                user.PushUri    = request.PushUri;
                user.DeviceName = request.DeviceName;
            }
            else
            {
                result.Result = AuthenticationResultType.NotRegistered;
            }
            _commandBuilder.ChangeUnderlyingObject(command, result);
            await remoteUser.Peer.SendCommand(command);
        }
        public IQueryable <User> GetUsers(out int total, int?offset = null, int?limit = null, bool?active = null, string fullname = null)
        {
            IQueryable <User> query = _userRepository;

            if (!string.IsNullOrWhiteSpace(fullname))
            {
                query = query.GetFinder()
                        .All(UserSpecifications.FirstNameContains(fullname).Or(UserSpecifications.LastNameContains(fullname)))
                        .AsQueryable();
            }

            if (active.HasValue)
            {
                query = query.Where(x => x.IsActive == active.Value);
            }

            total = query.Count();

            var users = query.Paging(offset, limit)
                        .OrderBy(x => x.FirstName + x.LastName).AsQueryable();

            return(users);
        }