public List <BillOfExchangeListDto> GetList(int take, int skip) { var list = BillOfExchangeRepository.Get(take, skip).ToList(); Dictionary <int, string> names = GetPartiesDictionary(GetPartiesIds(list)); return(list.ConvertAll(b => new BillOfExchangeListDto(b.Id, b.DrawerId, names[b.DrawerId], b.BeneficiaryId, names[b.BeneficiaryId], b.Amount))); }
public EndorsementServiceTest() { _billOfExchangeRepository = new BillOfExchangeRepository(); _endorsementRepository = new EndorsementRepository(); _billsOfExchangeService = new BillsOfExchangeService(_billOfExchangeRepository, _endorsementRepository, new PartyService(new PartyRepository())); _endorsementService = new EndorsementService(new EndorsementRepository(), _billsOfExchangeService); }
public void BillOfExchangeRepository_Get() { BillOfExchangeRepository sut = new BillOfExchangeRepository(); BillOfExchange[] result1 = sut.Get(10, 0).ToArray(); BillOfExchange[] result2 = sut.Get(10, 5).ToArray(); CollectionAssert.AreEqual(result1.Skip(5).Take(5), result2.Take(5)); }
public List <BillOfExchangeDetailDto> GetByDrawer(int drawerId) { List <BillOfExchange> list = BillOfExchangeRepository.GetByDrawerIds(new List <int> { drawerId }).FirstOrDefault()?.ToList() ?? new List <BillOfExchange>(); Dictionary <int, string> names = GetPartiesDictionary(GetPartiesIds(list)); return(list.ConvertAll(b => new BillOfExchangeDetailDto(b.Id, b.DrawerId, names[b.DrawerId], b.BeneficiaryId, names[b.BeneficiaryId], b.Amount))); }
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 void BillOfExchangeRepository_GetByDrawerIds() { BillOfExchangeRepository sut = new BillOfExchangeRepository(); IReadOnlyList <IEnumerable <BillOfExchange> > result = sut.GetByDrawerIds(new int[] { 14, 9 }); Assert.Multiple(() => { Assert.AreEqual(1, result.First().Count()); Assert.AreEqual(2, result.Last().Count()); }); }
public void BillOfExchangeRepository_GetByIds() { BillOfExchangeRepository sut = new BillOfExchangeRepository(); IReadOnlyList <BillOfExchange> result = sut.GetByIds(new int[] { 6, 7, 8 }); Assert.Multiple(() => { Assert.AreEqual(6, result.First().Id); Assert.AreEqual(8, result.Last().Id); }); }
public BillOfExchangeDetailDto GetBillOfExchange(int billId) { BillOfExchange bill = BillOfExchangeRepository.GetByIds(new List <int> { billId }).First(); BillOfExchangeCheckResult result = BillOfExchangeChecker.BillOfExchangeCheck(bill); if (!result.IsCorrect) { throw new Exception(result.Message); } Dictionary <int, string> names = GetPartiesDictionary(GetPartiesIds(new List <BillOfExchange> { bill })); return(new BillOfExchangeDetailDto(bill.Id, bill.DrawerId, names[bill.DrawerId], bill.BeneficiaryId, names[bill.BeneficiaryId], bill.Amount)); }
public List <EndorsmentListDto> GetByBillOfExhange(int billOfExhangeId) { IEnumerable <Endorsement> list = EndorsementRepository.GetByBillIds(new List <int> { billOfExhangeId }).FirstOrDefault()?.ToList() ?? new List <Endorsement>(); BillOfExchange billOfExchange = BillOfExchangeRepository.GetByIds(new List <int> { billOfExhangeId }).First(); var partyNamesDictionary = PartyRepository.GetByIds(list.Select(l => l.NewBeneficiaryId).Distinct().ToList()).ToDictionary(p => p.Id, p => p.Name); EndorsementCheckResult result = EndorsementChecker.CheckList(billOfExchange, list); if (!result.IsCorrect) { throw new Exception(result.Message); } return(list.Select(e => new EndorsmentListDto(e.Id, e.NewBeneficiaryId, partyNamesDictionary[e.NewBeneficiaryId])).ToList()); }
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))); }