public async Task <T> GetOrganization <T>(IOrganizationCustomer principal) where T : CustomerOrganizationOutput
 {
     return(await Repository.Queryable()
            .Where(x => x.CustomerId == principal.CustomerId && x.OrganizationId == principal.OrganizationId)
            .ProjectTo <T>(ProjectionMapping)
            .FirstOrDefaultAsync());
 }
        public async Task <BuyerAccountOutput> GetBuyerAccount(IOrganizationCustomer customer)
        {
            _logger.LogInformation(GetLogMessage("For customer: {0}; and organization: {1}"), customer.CustomerId, customer.OrganizationId);

            var y = await Repository
                    .Queryable()
                    .Include(x => x.OrganizationBuyerAccount)
                    .Where(x => x.OrganizationBuyerAccount.Id == customer.OrganizationId)
                    .ProjectTo <BuyerAccountOutput>(ProjectionMapping)
                    .FirstOrDefaultAsync();

            if (y == null)
            {
                _logger.LogInformation(GetLogMessage("No buyer account was found, creating one..."));
                var result = await PushCustomer(customer.OrganizationId, customer.CustomerId);

                _logger.LogDebug(GetLogMessage("{0} records updated in database"), result);

                if (result > 0)
                {
                    return(await GetBuyerAccount(customer));
                }
            }
            else
            {
                _logger.LogDebug(GetLogMessage("Buyer account found: {0}"), y.Id);
            }

            return(y);
        }
 public Task <CustomerCounts> GetCounts(IOrganizationCustomer principal)
 {
     return(Repository.Queryable()
            .Where(x => x.CustomerId == principal.CustomerId && x.OrganizationId == principal.OrganizationId)
            .ProjectTo <CustomerCounts>(ProjectionMapping)
            .FirstOrDefaultAsync());
 }
        public Task <string> GetAuthUrl(IOrganizationCustomer customer)
        {
            _logger.LogInformation(GetLogMessage("Getting Auth Url for customer {Customer}"), customer);

            var theCustomer = _organizationCustomerRepository.Queryable()
                              .Include(x => x.Organization)
                              .ThenInclude(x => x.OrganizationBuyerAccount)
                              .Include(x => x.Customer)
                              .ThenInclude(x => x.Person)
                              .ThenInclude(x => x.ApplicationUser)
                              .First(x =>
                                     x.OrganizationId == customer.OrganizationId && x.CustomerId == customer.CustomerId);

            var dict = new Dictionary <string, string>
            {
                { "client_id", _stripeSettings.ClientId },
                { "redirect_uri", _stripeSettings.RedirectUri },
                { "scope", "read_write" },
                { "response_type", "code" },
                { "state", customer.OrganizationId.ToString() },
                { "stripe_user[email]", theCustomer.Customer.Person.ApplicationUser.Email },
                { "stripe_user[first_name]", theCustomer.Customer.Person.FirstName },
                { "stripe_user[last_name]", theCustomer.Customer.Person.LastName },
                { "stripe_user[country]", theCustomer.Customer.Person.Iso2 },
                { "stripe_user[business_name]", theCustomer.Organization.Name },
                { "stripe_user[business_type]", "company" },
                // {"suggested_capabilities[]","card_payments,transfers,tax_reporting_us_1099_k" }
            };

            var url = $"https://connect.stripe.com/express/oauth/authorize{BuildQuerystring(dict)}";

            _logger.LogDebug(GetLogMessage("{Url}"), url);

            return(Task.FromResult(url));
        }
Esempio n. 5
0
 public Task <PackedList <T> > GetStories <T>(IOrganizationCustomer cu, StoryFilters filters)
     where T : CustomerStoryOutput
 {
     return(Repository.Queryable().ForOrganizationCustomer(cu)
            .ApplyWhereFilters(filters)
            .PaginateProjection <Story, T>(filters, ProjectionMapping));
 }
Esempio n. 6
0
 public RetainerController(
     IOrganizationCustomer customer,
     IServiceProvider serviceProvider, IRetainerService retainerService) : base(serviceProvider)
 {
     _customer        = customer;
     _retainerService = retainerService;
 }
Esempio n. 7
0
 public async Task <T> GetTimeEntry <T>(IOrganizationCustomer customer, Guid entryId) where T : CustomerTimeEntryOutput
 {
     return(await Repository.Queryable()
            .FindById(entryId)
            .ProjectTo <T>(ProjectionMapping)
            .FirstOrDefaultAsync());
 }
 public Task <T> GetOrganization <T>(IOrganizationCustomer cu) where T : CustomerOrganizationOutput
 {
     return(Repository.Queryable()
            .Where(x => x.Id == cu.OrganizationId)
            .ProjectTo <T>(ProjectionMapping)
            .FirstOrDefaultAsync());
 }
Esempio n. 9
0
 public Task <T> GetWorkOrder <T>(IOrganizationCustomer customer, Guid orderId) where T : BuyerWorkOrderOutput
 {
     return(Repository.Queryable().Where(x =>
                                         x.CustomerId == customer.CustomerId && x.CustomerOrganizationId == customer.OrganizationId && x.Id == orderId)
            .ProjectTo <T>(ProjectionMapping)
            .FirstAsync());
 }
        public async Task <RetainerResult> SetupRetainer(IOrganizationCustomer customer, Guid projectId,
                                                         CreateRetainerOptions options)
        {
            _logger.LogInformation(GetLogMessage("Customer:{0}; Project:{1}"), customer.CustomerId, projectId);

            var retVal = new RetainerResult();

            var project = await _projects.Queryable()
                          .ForOrganizationCustomer(customer)
                          .Include(x => x.CustomerAccount)
                          .Where(x => x.Id == projectId)
                          .FirstAsync();

            var retainer = new ProjectRetainerIntent()
            {
                AccountManagerId       = project.CustomerAccount.AccountManagerId,
                ProviderOrganizationId = project.CustomerAccount.AccountManagerOrganizationId,
                CustomerId             = project.CustomerAccount.CustomerId,
                CustomerOrganizationId = project.CustomerAccount.CustomerOrganizationId,
                ProjectId      = projectId,
                TopOffAmount   = options.TopOffAmount,
                CurrentBalance = 0
            };

            var records = await Repository.InsertAsync(retainer, true);

            if (records > 0)
            {
                retVal.Succeeded  = true;
                retVal.RetainerId = projectId;
            }

            return(retVal);
        }
Esempio n. 11
0
 public BalanceController(IServiceProvider serviceProvider,
                          IOrganizationCustomer customer,
                          ICustomerBalanceService balanceService) : base(serviceProvider)
 {
     _customer       = customer;
     _balanceService = balanceService;
 }
Esempio n. 12
0
 public InvoiceController(IProjectInvoiceService invoiceService,
                          IOrganizationCustomer customer,
                          IServiceProvider serviceProvider) : base(serviceProvider)
 {
     _invoiceService = invoiceService;
     _customer       = customer;
 }
Esempio n. 13
0
 public static IQueryable <TimeEntry> ForOrganizationCustomer(this IQueryable <TimeEntry> entities,
                                                              IOrganizationCustomer cu)
 {
     return(entities.Where(x =>
                           x.CustomerId == cu.CustomerId &&
                           x.CustomerOrganizationId == cu.OrganizationId));
 }
Esempio n. 14
0
 public Task <T> GetProject <T>(IOrganizationCustomer organizationCustomer, Guid projectId) where T : CustomerProjectOutput, new()
 {
     return(Repository.Queryable()
            .ForOrganizationCustomer(organizationCustomer)
            .FindById(projectId)
            .ProjectTo <T>(ProjectionMapping)
            .FirstOrDefaultAsync());
 }
Esempio n. 15
0
        public async Task <bool> CreateAccountComment(IOrganizationCustomer customer, int accountId, CommentInput input)
        {
            var account = await _accountRepository.Queryable().ForOrganizationCustomer(customer)
                          .Where(x => x.BuyerNumber == accountId)
                          .FirstAsync();

            return(await CreateAccountComment(account, input, customer.OrganizationId));
        }
Esempio n. 16
0
 public Task <bool> DoesContractAlreadyExist(IOrganizationContractor co, IOrganizationCustomer cu, Guid projectId)
 {
     return(Repository.Queryable()
            .ForOrganizationCustomer(cu)
            .ForOrganizationContractor(co)
            .FindById(projectId)
            .AnyAsync());
 }
Esempio n. 17
0
 public Task <PackedList <T> > GetFixedPriceProposals <T>(IOrganizationCustomer cu, ProposalFilters filters
                                                          ) where T : CustomerFixedPriceProposalOutput
 {
     return(Repository.Queryable()
            .ForOrganizationCustomer(cu)
            .ApplyWhereFilters(filters)
            .PaginateProjection <FixedPriceProposal, T>(filters, ProjectionMapping));
 }
Esempio n. 18
0
 public Task <T> GetProposal <T>(IOrganizationCustomer cu, Guid proposalId) where T : CustomerFixedPriceProposalOutput
 {
     return(Repository.Queryable()
            .ForOrganizationCustomer(cu)
            .FindById(proposalId)
            .ProjectTo <T>(ProjectionMapping)
            .FirstOrDefaultAsync());
 }
Esempio n. 19
0
        public async Task <bool> CreateStoryComment(IOrganizationCustomer customer, Guid storyId, CommentInput input)

        {
            var story = await _storyRepository.Queryable().ForOrganizationCustomer(customer)
                        .FindById(storyId).FirstAsync();

            return(await CreateStoryComment(story, input, customer.OrganizationId));
        }
 public BuyerAccountController(
     IServiceProvider serviceProvider,
     IBuyerAccountService buyerService,
     IOrganizationCustomer customer) : base(serviceProvider)
 {
     _buyerService = buyerService;
     _customer     = customer;
 }
Esempio n. 21
0
 public Task <RetainerOutput> GetRetainer(IOrganizationCustomer customer, Guid retainerId)
 {
     return(Repository.Queryable().Where(x => x.CustomerId == customer.CustomerId &&
                                         x.CustomerOrganizationId == customer.OrganizationId &&
                                         x.ProjectId == retainerId)
            .ProjectTo <RetainerOutput>(ProjectionMapping)
            .FirstOrDefaultAsync());
 }
Esempio n. 22
0
 public Task <PackedList <T> > GetWorkOrders <T>(IOrganizationCustomer customer, WorkOrderFilters filters) where T : BuyerWorkOrderOutput
 {
     return(Repository.Queryable()
            .ApplyWhereFilters(filters)
            .Where(x => x.CustomerId == customer.CustomerId &&
                   x.CustomerOrganizationId == customer.OrganizationId)
            .PaginateProjection <WorkOrder, T>(filters, ProjectionMapping));
 }
Esempio n. 23
0
 public WorkOrderController(
     IOrganizationCustomer customer,
     IWorkOrderService workOrderService,
     IServiceProvider serviceProvider) : base(serviceProvider)
 {
     _customer         = customer;
     _workOrderService = workOrderService;
 }
Esempio n. 24
0
        public StoryController(
            IStoryService storyService,
            IOrganizationCustomer customer,
            IServiceProvider serviceProvider) : base(serviceProvider)

        {
            _customer     = customer;
            _storyService = storyService;
        }
Esempio n. 25
0
 public Task <List <T> > GetStories <T>(IOrganizationCustomer cu, Guid?[] uniqueStoryIds)
     where T : CustomerStoryOutput
 {
     return(Repository.Queryable()
            .ForOrganizationCustomer(cu)
            .Where(x => uniqueStoryIds.Contains(x.Id))
            .ProjectTo <T>(ProjectionMapping)
            .ToListAsync());
 }
Esempio n. 26
0
 public Task <T> GetStory <T>(IOrganizationCustomer cu, Guid storyId)
     where T : CustomerStoryOutput
 {
     return(Repository.Queryable()
            .FindById(storyId)
            .ForOrganizationCustomer(cu)
            .ProjectTo <T>(ProjectionMapping)
            .FirstOrDefaultAsync());
 }
Esempio n. 27
0
 public TimeController(IServiceProvider serviceProvider,
                       IOrganizationCustomer orgCustomer,
                       ITimeMatrixService timeService,
                       IChartService chartService) : base(serviceProvider)
 {
     _orgCustomer  = orgCustomer;
     _timeService  = timeService;
     _chartService = chartService;
 }
Esempio n. 28
0
        public async Task <T> UpdateWorkOrder <T>(IOrganizationCustomer customer, Guid orderId, UpdateWorkOrderInput input)
            where T : BuyerWorkOrderOutput
        {
            var workOrder = await Repository.Queryable()
                            .Where(x => x.CustomerId == customer.CustomerId && x.Id == orderId)
                            .FirstAsync();

            return(await UpdateWorkOrder <T>(workOrder, input));
        }
        public async Task <ContractResult> RestartContract(IOrganizationCustomer cu, Guid contractId)
        {
            _logger.LogInformation(GetLogMessage("CU: {0}; Contract: {1}"), cu.OrganizationId, contractId);
            var contract = await Repository.Queryable().ForOrganizationCustomer(cu)
                           .FindById(contractId)
                           .FirstAsync();

            return(await RestartContract(contract));
        }
Esempio n. 30
0
 public Task <List <T> > GetProjects <T>(IOrganizationCustomer cu, Guid[] uniqueProjectIds) where T : CustomerProjectOutput, new()
 {
     return(Repository.Queryable()
            .ForOrganizationCustomer(cu)
            .Where(x => uniqueProjectIds.Contains(x.Id))
            .OrderByDescending(x => x.Updated)
            .ProjectTo <T>(ProjectionMapping)
            .ToListAsync());
 }