示例#1
0
        // GET: Fundraiser
        public ActionResult Index(Guid?id)
        {
            if (!id.HasValue)
            {
                var campaigns = _campaignRepository.GetAll().ToList();

                var model = new FundraisersViewModel();
                model.Campaigns = AutoMapper.Mapper.Map <List <Campaign>, List <CampaignViewModel> >(campaigns);
                foreach (var campaign in model.Campaigns)
                {
                    var fundraisers = _fundraiserRepository.FindByCampaign(campaign.Id).ToList();
                    campaign.Fundraisers = AutoMapper.Mapper.Map <List <Fundraiser>, List <FundraiserViewModel> >(fundraisers);
                }

                return(View(model));
            }
            var fundraiser = _fundraiserRepository.FindById(id.Value);

            if (fundraiser == null)
            {
                return(HttpNotFound());
            }

            var fundraiserViewModel = AutoMapper.Mapper.Map <Fundraiser, FundraiserViewModel>(fundraiser);
            var donations           = _donationRepository.GetByFundraiser(fundraiser.Id).ToList();

            fundraiserViewModel.Donations = AutoMapper.Mapper.Map <List <Donation>, List <DonationViewModel> >(donations);

            return(View("Detail", fundraiserViewModel));
        }
 protected override List <Core.Entities.Fundraiser> HandleCore(GetByCampaignId request)
 {
     return(_fundraiserRepository.FindByCampaign(request.CampaignId).ToList());
 }