Example #1
0
        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)));
        }