public VirtualNumberAssociation Generate(IVirtualNumberRequest virtualNumberRequest)
        {
            var availableNumbers = _virtualNumberRepository.Get()
                                   .Where(number => number.Purpose.Id.Equals(virtualNumberRequest.PurposeId))
                                   .Include(number => number.VirtualPhoneNumber);

            var virtualNumbersUsedBySeeker = _virtualNumberAssociationRepository.Get()
                                             .Where(
                association => association.Caller.Id == virtualNumberRequest.Caller.Id &&
                association.VirtualNumber.Purpose.Id == virtualNumberRequest.PurposeId);

            var numbersUsedBySeeker = virtualNumbersUsedBySeeker.Select(
                number => number.VirtualNumber).Include(number => number.VirtualPhoneNumber).ToList();

            var availableNumber = availableNumbers.ToList()
                                  .Except((numbersUsedBySeeker), new VirtualNumberComparer()).FirstOrDefault();

            if (availableNumber == null)
            {
                throw new ApplicationException("No more numbers available!");
            }

            var newAssociation = new VirtualNumberAssociation
            {
                Caller        = virtualNumberRequest.Caller,
                Callee        = virtualNumberRequest.Callee,
                State         = new InUse(),
                VirtualNumber = availableNumber,
                BabajobJobId  = virtualNumberRequest.BabajobJobId
            };

            this.Save(newAssociation);

            return(newAssociation);
        }
 public VirtualNumberAssociation Get(IVirtualNumberRequest virtualNumberRequest)
 {
     return(this.Get()
            .Include(a => a.VirtualNumber.VirtualPhoneNumber)
            .FirstOrDefault(
                association => association.Caller.Id
                == virtualNumberRequest.Caller.Id &&
                association.Callee.Id
                == virtualNumberRequest.Callee.Id &&
                association.BabajobJobId
                == virtualNumberRequest.BabajobJobId));
 }