public async Task <GetDeliveryDemandsResult> GetDeliveryDemands(GetDeliveryDemandsRequest request) { using IDbConnection connection = _sqlConnectionFactory.CreateConnection(); connection.Open(); var sql = new QueryBuilder() .SelectColumns(DeliveryDemandEntity.TableName, DeliveryDemandsTableColumns) .Where("(@CampaignName IS NULL OR CampaignName = @CampaignName)") .And("(@ProcessId IS NULL OR ProcessId = @ProcessId)") .And("(@PickupUsername IS NULL OR PickupUsername = @PickupUsername)") .And("(@DestinationUsername IS NULL OR DestinationUsername = @DestinationUsername)") .And("(@Status IS NULL OR Status = @Status)") .OrderBy("TimeCreated", "DESC") .Build(); var deliveryDemandEntities = (await connection.QueryAsync <DeliveryDemandEntity>(sql, request)).ToList(); List <DeliveryDemand> deliveryDemands = new List <DeliveryDemand>(); foreach (var entity in deliveryDemandEntities) { var pickupLocation = await _locationStore.GetLocation(entity.PickupUsername); var destinationLocation = await _locationStore.GetLocation(entity.DestinationUsername); var deliveryDemand = ToDeliveryDemand(entity, pickupLocation, destinationLocation); deliveryDemands.Add(deliveryDemand); } return(new GetDeliveryDemandsResult { DeliveryDemands = deliveryDemands }); }
public async Task <MatchDeliveryDemandResult> MatchDeliveryDemand(MatchDeliveryDemandRequest request) { var getDeliveryDemandsRequest = new GetDeliveryDemandsRequest { Status = "Pending" }; var getDeliveryDemandsResult = await _transactionStore.GetDeliveryDemands(getDeliveryDemandsRequest); var deliveryDemands = getDeliveryDemandsResult.DeliveryDemands; var matchDeliveryDemandResult = await _matchingService.MatchUserToDeliveryDemand(deliveryDemands, request); return(matchDeliveryDemandResult); }
public async Task <IActionResult> GetDeliveryDemands(string processId = null, string campaignName = null, string pickupUsername = null, string destinationUsername = null, string status = null) { var request = new GetDeliveryDemandsRequest { ProcessId = processId, CampaignName = campaignName, PickupUsername = pickupUsername, DestinationUsername = destinationUsername, Status = status }; var deliveryDemands = await _transactionService.GetDeliveryDemands(request); return(Ok(deliveryDemands)); }
private async Task <Process> BuildProcess(string processId) { Process process = await _transactionStore.GetProcess(processId); var getContributionsRequest = new GetContributionsRequest { ProcessId = processId }; var contributions = await _transactionStore.GetContributions(getContributionsRequest); var donorContribution = contributions.Contributions.Find(contribution => contribution.Type != "Delivery"); var getDeliveryDemands = new GetDeliveryDemandsRequest { ProcessId = processId }; var deliveryDemands = await _transactionStore.GetDeliveryDemands(getDeliveryDemands); if (deliveryDemands.DeliveryDemands.Count != 0) { var deliveryDemand = deliveryDemands.DeliveryDemands[0]; contributions.Contributions.ForEach(contribution => { if (contribution.Type == "Delivery") { deliveryDemand.AddComponent(contribution); } }); process.AddComponent(deliveryDemand); } process.AddComponent(donorContribution); process.SetStore(_transactionStore); return(process); }
public async Task <GetDeliveryDemandsResult> GetDeliveryDemands(GetDeliveryDemandsRequest request) { var getDeliveryDemandsResult = await _transactionStore.GetDeliveryDemands(request); return(getDeliveryDemandsResult); }