public MockDonationRepository(FundContext dbContext,
                                      IFundraiserRepository fundraiserRepository,
                                      IDonorRepository donorRepository)
        {
            this.dbContext            = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
            this.fundraiserRepository = fundraiserRepository ?? throw new ArgumentNullException(nameof(fundraiserRepository));
            this.donorRepository      = donorRepository ?? throw new ArgumentNullException(nameof(donorRepository));

            Donations = new List <Donation> {
                new Donation {
                    FundraiserId = fundraiserRepository.GetFundraisersAsync().Result.First().Id,
                    DonorId      = donorRepository.GetDonorsAsync().Result.First().Id,
                    Amount       = 10,
                    DonationDate = DateTimeOffset.Now
                },

                new Donation {
                    FundraiserId = fundraiserRepository.GetFundraisersAsync().Result.First().Id,
                    DonorId      = donorRepository.GetDonorsAsync().Result.Last().Id,
                    Amount       = 40,
                    DonationDate = DateTimeOffset.Now
                },
            };
        }
Пример #2
0
        public async Task <IActionResult> Index(Guid?id)
        {
            DonationCreateViewModel vm = new DonationCreateViewModel();

            vm.Donation = new DonationDto();
            if (id.HasValue)
            {
                vm.Donation.FundraiserId = id.Value;
                var fundraiser = await fundraiserService.GetFundraiserAsync(id.Value);

                vm.Fundraiser = mapper.Map <FundraiserDto>(fundraiser);
            }
            else
            {
                var results = await fundraiserService.GetFundraisersAsync();

                vm.Fundraisers = mapper.Map <IEnumerable <FundraiserDto> >(results)
                                 .Select(f => new SelectListItem {
                    Text = f.Name, Value = f.Id.ToString()
                })
                                 .ToList();
            }
            return(View(vm));
        }
        public async Task <IActionResult> List()
        {
            var results = await fundraiserService.GetFundraisersAsync();

            return(View(mapper.Map <IEnumerable <FundraiserDto> >(results)));
        }