public IEnumerable <BillOfExchangeDto> GetByBeneficiaryId(int beneficiaryId) { var billsOfExchange = _repository.GetByBeneficiaryIds(new[] { beneficiaryId }).FirstOrDefault(); var billsIds = _endorsementRepository.GetByNewBeneficiaryIds(new[] { beneficiaryId }).SelectMany( x => x.Where(y => y.PreviousEndorsementId == null).Select(y => y.BillId)) .Distinct().ToImmutableList(); return(MapToDto((billsOfExchange ?? new List <BillOfExchange>()).Concat(_repository.GetByIds(billsIds)))); }
public IEnumerable <EndorsementDto> GetEndorsementsForBill(int billId) { List <EndorsementDto> endorsements = (from party in partyRepository.Get(int.MaxValue, 0) join endorsement in endorsementRepository.Get(int.MaxValue, 0) on party.Id equals endorsement .NewBeneficiaryId where endorsement.BillId == billId select new EndorsementDto { NewBeneficiaryId = party.Id, NewBeneficiary = party.Name, Id = endorsement.Id, BillId = endorsement.BillId, PreviousEndorsementId = endorsement.PreviousEndorsementId }).ToList(); if (!endorsements.Any()) { return(new List <EndorsementDto>()); } BillOfExchange bill = billOfExchangeRepository.GetByIds(new List <int> { billId }).Single(); ValidateEndorsements(billId, endorsements, bill); return(endorsements); }