public async Task <AdvancedGetContractResponse> AdvancedGetContracts(string sorts, string filters, int?page, int?pageSize)
        {
            var sieveModel = new SieveModel()
            {
                PageSize = pageSize,
                Sorts    = sorts,
                Page     = page,
                Filters  = filters
            };

            var contracts = await _repoWrapper.Contract.FindAllAsync();

            if (contracts == null || contracts.Any() == false)
            {
                //return null if no contract is found
                return(new AdvancedGetContractResponse()
                {
                    ResultList = null,
                    CurrentPage = 1,
                    TotalPage = 1
                });
            }

            var resultResponses = new List <GetContractResponse>();

            foreach (var contract in contracts)
            {
                resultResponses.Add(GetContractResponse.ResponseFromEntity(contract));
            }

            //Apply filter, sort
            var result = _sieveProcessor.Apply(sieveModel, resultResponses.AsQueryable(), applyPagination: false).ToList();

            var response = new AdvancedGetContractResponse()
            {
                CurrentPage = page ?? 1,
                TotalPage   = (int)Math.Ceiling((double)result.Count / pageSize ?? 1),
                //Apply pagination
                ResultList = _sieveProcessor
                             .Apply(sieveModel, result.AsQueryable(), applyFiltering: false, applySorting: false).ToList()
            };

            //Return List of result
            return(response);
        }
示例#2
0
 public DeleteContractRequest(GetContractResponse contract)
 {
     Contract = contract;
 }
        private async Task <GetContractResponse> LoadContract(Contract contract)
        {
            GetContractResponse resp = new GetContractResponse();

            ContractModel cm = new ContractModel()
            {
                CurrentPayPeriod     = new DateTime(2017, 11, 3),
                AccountingContractId = contract.AccountingContractId,
                ContractEndDate      = contract.ContractEndDate,
                ContractId           = contract.ContractId,
                ContractName         = contract.ContractName,
                ContractNumber       = contract.ContractNumber,
                ContractStartDate    = contract.ContractStartDate,
                InitialDeposit       = contract.InitialDeposit,
                Is1099Vendor         = contract.Is1099Vendor,
                IsDirectDeposit      = contract.IsDirectDeposit,
                PayrollId            = contract.PayrollId,
                PercentRetained      = contract.PercentRetained,
                ResponsibleParty     = contract.ResponsibleParty,
                TIN      = contract.TIN,
                IsActive = contract.IsActive
            };

            resp.CurrentContract = cm;

            //setup the multiple rows of dataas well
            var drivers = await repository.GetDriverContractsByContractId(contract.ContractId);

            foreach (DriverContract dc in drivers)
            {
                resp.CurrentContract.AssignedDrivers.Add(new AssignedDriverModel
                {
                    DriverContractId = dc.DriverContractId,
                    DriverFullName   = dc.Driver.FirstName + " " + dc.Driver.LastName,
                    DriverId         = dc.DriverId,
                    EndDate          = dc.EndDate,
                    StartDate        = dc.StartDate
                });
            }

            var trucks = await repository.GetContractTrucksByContractId(contract.ContractId);

            foreach (ContractTruck ct in trucks)
            {
                resp.CurrentContract.AssignedTrucks.Add(new AssignedTruckModel
                {
                    ContractTruckId = ct.ContractTruckId,
                    TruckId         = ct.TruckId,
                    TruckNumber     = ct.Truck.TruckNumber,
                    EndDate         = ct.EndDate,
                    StartDate       = ct.StartDate
                });
            }


            var finances = await repository.GetContractFinanceAgreementsByContractId(contract.ContractId);

            //var finances = await _context.ContractFinanceAgreement.Where(dc => dc.ContractId == contract.ContractId).ToListAsync();
            foreach (ContractFinanceAgreement cfa in finances)
            {
                resp.CurrentContract.AssignedFinanceAgreements.Add(new AssignedFinanceAgreementModel
                {
                    ContractFinanceAgreementId = cfa.ContractFinanceAgreementId,
                    FinanceAgreementName       = cfa.FinanceAgreementName,
                    FinanceTypeName            = cfa.FinanceType.FinanceTypeName,
                    PaymentAmount    = cfa.PaymentAmount,
                    RemainingBalance = cfa.RemainingBalance,
                    LoanAmount       = cfa.LoanAmount,
                    EndDate          = cfa.EndDate,
                    StartDate        = cfa.StartDate
                });

                resp.CurrentContract.TotalLoans    = resp.CurrentContract.TotalLoans + cfa.LoanAmount;
                resp.CurrentContract.TotalToSettle = resp.CurrentContract.TotalToSettle + cfa.RemainingBalance;
            }



            return(resp);
        }