public void BillOfExchangeRepository_GetByBeneficiaryIds() { BillOfExchangeRepository sut = new BillOfExchangeRepository(); IReadOnlyList <IEnumerable <BillOfExchange> > result = sut.GetByBeneficiaryIds(new int[] { 13 }); BillOfExchange bill1 = result.Single().First(); BillOfExchange bill2 = result.Single().Last(); Assert.AreEqual(2, bill1.Id); Assert.AreEqual(4, bill2.Id); }
public List <BillOfExchangeDetailDto> GetByBeneficiary(int beneficiaryId) { List <BillOfExchange> allBillsByBeneficiary = BillOfExchangeRepository.GetByBeneficiaryIds(new List <int> { beneficiaryId }).FirstOrDefault()?.ToList() ?? new List <BillOfExchange>(); var billIdsWithAtLeastOneEndorsement = new HashSet <int>(EndorsementRepository.GetByBillIds(allBillsByBeneficiary.ConvertAll(b => b.Id)).Select(e => e.First().BillId)); var billsByBeneficiaryWithoutAtLeastOneEndorsement = allBillsByBeneficiary.Where(b => !billIdsWithAtLeastOneEndorsement.Contains(b.Id)).ToList(); var endorsementsWithBenficiaryList = EndorsementRepository.GetByNewBeneficiaryIds(new List <int> { beneficiaryId }).FirstOrDefault()?.ToList(); IReadOnlyList <IEnumerable <Endorsement> > allEndorsementByBillList = EndorsementRepository.GetByBillIds(endorsementsWithBenficiaryList.Select(e => e.BillId).Distinct().ToList()); var lastEndorsementWithBeneficiaryList = allEndorsementByBillList.Select(el => el.Last()).Where(el => el.NewBeneficiaryId == beneficiaryId).ToList(); var billsByLastEndorsement = BillOfExchangeRepository.GetByIds(lastEndorsementWithBeneficiaryList.Select(e => e.BillId).ToList()).ToList(); var finishedList = billsByBeneficiaryWithoutAtLeastOneEndorsement.Concat(billsByLastEndorsement).Distinct().ToList(); Dictionary <int, string> names = GetPartiesDictionary(GetPartiesIds(finishedList)); return(finishedList.ConvertAll(b => new BillOfExchangeDetailDto(b.Id, b.DrawerId, names[b.DrawerId], b.BeneficiaryId, names[b.BeneficiaryId], b.Amount))); }