public async Task <Campaign> MatchUserToCampaign(List <Campaign> campaigns, MatchCampaignRequest request) { if (campaigns.Count == 0) { return(null); } if (request.Type == "Donation") { List <Campaign> sortedCampaigns = campaigns.OrderBy(x => x.CompletedCount).ToList(); return(sortedCampaigns[0]); } else if (request.Type == "Volunteering") { var campaignsETA = new List <(double, Campaign)>(); foreach (var campaign in campaigns) { var eta = await _routingService.GetETA(request.Location, campaign.Location, request.TransportationType); campaignsETA.Add((eta, campaign)); } //Sort the campaigns from closest to farthest and choose the closest campaignsETA.Sort(); return(campaignsETA[0].Item2); } else { throw new BadRequestException("Invalid Request Type"); } }
private async void FindCampaignMatchAsync(object sender, EventArgs e) { var tag = ((Button)sender).Tag.ToString(); var matchCampaignRequest = new MatchCampaignRequest { Type = "Donation", Category = tag }; matchedCampaign = await client.MatchCampaign(matchCampaignRequest); Navigate(DonationCampaignMatchPanel); }
public async Task <Campaign> MatchCampaign(MatchCampaignRequest request) { var getCampaignsRequest = new GetCampaignsRequest { Status = "Active", Type = request.Type, Category = request.Category }; var getCampaignsResult = await _transactionStore.GetCampaigns(getCampaignsRequest); var campaigns = getCampaignsResult.Campaigns; var campaign = await _matchingService.MatchUserToCampaign(campaigns, request); return(campaign); }
public async Task <Campaign> MatchCampaign(MatchCampaignRequest matchCampaignRequest) { string json = JsonConvert.SerializeObject(matchCampaignRequest); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "api/transactions/campaigns/match") { Content = new StringContent(json, Encoding.UTF8, "application/json") }; HttpResponseMessage responseMessage = await _httpClient.SendAsync(request); await EnsureSuccessOrThrowAsync(responseMessage); string recievedJson = await responseMessage.Content.ReadAsStringAsync(); var campaign = JsonConvert.DeserializeObject <Campaign>(recievedJson); return(campaign); }
private async void VolunteeringInfoPanel_FindMatch_Click(object sender, EventArgs e) { var location = new Location { Longitude = Convert.ToDouble(VolunteeringInfoPanel_Longitude.Text), Latitude = Convert.ToDouble(VolunteeringInfoPanel_Latitude.Text) }; var matchCampaignRequest = new MatchCampaignRequest { Type = "Volunteering", Category = volunteeringTag, TransportationType = transportationType[VolunteeringInfoPanel_TransportationType.Text], Location = location }; matchedCampaign = await client.MatchCampaign(matchCampaignRequest); Navigate(VolunteeringCampaignMatchPanel); }
public async Task <IActionResult> MatchCampaign([FromBody] MatchCampaignRequest request) { var campaign = await _transactionService.MatchCampaign(request); return(Ok(campaign)); }