Example #1
0
        public async Task <GetContributionsResult> GetContributions(GetContributionsRequest request)
        {
            using IDbConnection connection = _sqlConnectionFactory.CreateConnection();
            connection.Open();

            var sql = new QueryBuilder()
                      .SelectColumns(ContributionEntity.TableName, ContributionsTableColumns)
                      .Where("(@Username IS NULL OR Username =  @Username)")
                      .And("(@ProcessId IS NULL OR ProcessId =  @ProcessId)")
                      .And("(@DeliveryDemandId IS NULL OR DeliveryDemandId =  @DeliveryDemandId)")
                      .And("(@Type IS NULL OR Type =  @Type)")
                      .And("(@Status IS NULL OR Status =  @Status)")
                      .OrderBy("TimeCreated", "DESC")
                      .Build();

            var campaignEntities = (await connection.QueryAsync <ContributionEntity>(sql, request)).ToList();

            List <Contribution> contributions = new List <Contribution>();

            foreach (var entity in campaignEntities)
            {
                var location = await _locationStore.GetLocation(entity.Username);

                var contribution = ToContribution(entity, location);
                contributions.Add(contribution);
            }

            return(new GetContributionsResult
            {
                Contributions = contributions
            });
        }
        public async Task <IActionResult> GetContributions(string username = null, string processId = null, string deliveryDemandId = null, string type = null, string status = null)
        {
            var request = new GetContributionsRequest
            {
                Username         = username,
                ProcessId        = processId,
                DeliveryDemandId = deliveryDemandId,
                Type             = type,
                Status           = status
            };
            var contributions = await _transactionService.GetContributions(request);

            return(Ok(contributions));
        }
Example #3
0
        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);
        }
Example #4
0
        public async Task <GetContributionsResult> GetContributions(GetContributionsRequest request)
        {
            var getContributionsResult = await _transactionStore.GetContributions(request);

            return(getContributionsResult);
        }