// 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 bool HandleCore(Donate request) { var fundraiser = _fundraiserRepository.FindById(request.FundraiserId); var campaign = _campaignRepository.FindById(fundraiser.CampaignId); if (request.DonationAmount > 0) { try { var chargeService = new StripeChargeService(); var charge = chargeService.Create(new StripeChargeCreateOptions() { Amount = request.DonationAmount * 100, Currency = "usd", Description = fundraiser.Name, SourceTokenOrExistingSourceId = request.StripeToken }); var donation = _donationRepository.Create(campaign, fundraiser, DonationStatus.Completed, request.DonationAmount, "usd", request.DonationAmount, request.UserId, request.DonorDisplayName, charge.Id); var integrationEvent = new DonationCreatedIntegrationEvent(donation.DonorUserId, donation.FundraiserId, donation.Amount, donation.DonorDisplayName); _eventBus.Publish(integrationEvent); // not tested; maybe IEventBus should be named something else since EasyNetQ already has an IEventBus; perhaps Publish(e) should be Publish<T>(e)? } catch (InvalidOperationException) { return(false); // maybe should return json with validation info? } return(true); } else { return(false); } }
// GET: Profile public ActionResult Index() { if (!User.Identity.IsAuthenticated) { return(Redirect("/")); } string userId = User.Identity.GetUserId(); var model = new ProfileViewModel(); var donations = _donationRepository.GetByDonor(userId).ToList(); model.Donations = AutoMapper.Mapper.Map <List <Donation>, List <DonationViewModel> >(donations); // a better way? this is not efficient foreach (var donation in model.Donations) { var fundraiser = _fundraiserRepository.FindById(donation.FundraiserId); if (fundraiser != null) { donation.FundraiserName = fundraiser.Name; } var campaign = _campaignRepository.FindById(donation.CampaignId); if (campaign != null) { donation.CampaignName = campaign.Name; } } var fundraisers = _fundraiserRepository.FindByCreator(userId).ToList(); model.Fundraisers = AutoMapper.Mapper.Map <List <Fundraiser>, List <FundraiserViewModel> >(fundraisers); return(View(model)); }
public void CreateFundraiser() { var fundraiser = _fundraiserRepository.Create("test fundraiser", testCampaign.Id, FundraiserType.Individual, "test"); Assert.IsTrue(fundraiser.Name == "test fundraiser", "name matches"); Assert.IsTrue(fundraiser.Id != null && fundraiser.Id.ToString() != "00000000-0000-0000-0000-000000000000", "id is set"); Assert.IsTrue(fundraiser.CampaignId == testCampaign.Id, "campaign id is set"); //Assert.IsFalse(campaign.IsActive, "'test campaign' was created but is not active"); Console.WriteLine("fundraiser.Id: " + fundraiser.Id); var fundraiser2 = _fundraiserRepository.FindById(fundraiser.Id); Assert.IsInstanceOfType(fundraiser2, typeof(Fundraiser)); Assert.IsTrue(fundraiser.Name == fundraiser2.Name); Assert.IsTrue(fundraiser2.CampaignId == testCampaign.Id); Console.WriteLine("type: " + fundraiser2.FundraiserType); }
protected override bool HandleCore(Update request) { try { var fundraiser = _fundraiserRepository.FindById(request.Id); fundraiser.Name = request.Name; fundraiser.Description = request.Description; fundraiser.IsActive = request.IsActive; _fundraiserRepository.Update(fundraiser); } catch { return(false); } return(true); }
protected override Core.Entities.Fundraiser HandleCore(GetById request) { return(_fundraiserRepository.FindById(request.Id)); }