public Task <T> GetAgreement <T>(IMarketingAgencyOwner marketingAgencyOwner, Guid providerOrganizationId) where T : MarketingAgreementOutput { return(Repository.Queryable().Where(x => x.ProviderOrganizationId == providerOrganizationId && x.MarketingOrganizationId == marketingAgencyOwner.OrganizationId) .Where(x => x.Status != AgreementStatus.Rejected) .ProjectTo <T>(ProjectionMapping) .FirstOrDefaultAsync()); }
public Task <T> GetLead <T>(IMarketingAgencyOwner agencyOwner, Guid leadId) where T : AgencyOwnerLeadOutput { return(Repository.Queryable() .Where(x => x.Id == leadId && x.MarketerOrganizationId == agencyOwner.OrganizationId && x.IsInternal == false) .ProjectTo <T>(ProjectionMapping) .FirstAsync()); }
public Task <T> GetMarketingContract <T>(IMarketingAgencyOwner ao, Guid contractId) where T : AgencyOwnerMarketingContractOutput { return(Repository.Queryable().ForAgencyOwner(ao) .FindById(contractId) .ProjectTo <T>(ProjectionMapping) .FirstOrDefaultAsync()); }
public Task <List <T> > GetAgreements <T>(IMarketingAgencyOwner marketingAgencyOwner) where T : MarketingAgreementOutput { return(Repository.Queryable().Where(x => x.MarketingOrganizationId == marketingAgencyOwner.OrganizationId) .Where(x => x.Status != AgreementStatus.Rejected) .ProjectTo <T>(ProjectionMapping) .ToListAsync()); }
public async Task <MarketingAgencyOwnerChartOutput> GetMarketingChartData(IMarketingAgencyOwner owner, TimeMatrixFilters filters, ChartParams chartParams) { var result = await _matrixService.GetMarketingAgencyComposedOutput(owner, filters); var status = result.Matrix .ToStatusData <MarketingAgencyOwnerTimeMatrixOutput, MarketingAgencyOwnerChartDataItem>() .FillMissingDays(chartParams.DateBreakdown, filters).TopLevelGrouping(chartParams.DateBreakdown) .SecondLevelGrouping(chartParams.DateBreakdown); var ma = result.Matrix.ToMaData <MarketingAgencyOwnerTimeMatrixOutput, AgencyOwnerOrganizationMarketerOutput, MarketingAgencyOwnerChartDataItem>(result.Marketers). FillMissingDays(chartParams.DateBreakdown, filters). TopLevelGrouping(chartParams.DateBreakdown). SecondLevelGrouping(chartParams.DateBreakdown); return(new MarketingAgencyOwnerChartOutput { Ma = ma, Status = status, CurrentBreakdown = "ma", CurrentDateRange = chartParams.DateBreakdown == DateBreakdown.ByMonth ? "m0" : "w0", DateRanges = GetDateRange(chartParams.DateBreakdown, ma), Breakdowns = new Dictionary <string, string> { { "ma", "By Marketer" }, { "status", "By Status" } } }); }
public Task <PackedList <T> > GetMarketingContracts <T>(IMarketingAgencyOwner ao, ContractFilters filters) where T : AgencyOwnerMarketingContractOutput { return(Repository.Queryable().ForAgencyOwner(ao) .ApplyWhereFilters(filters) .OrderByDescending(x => x.Updated) .PaginateProjection <Contract, T>(filters, ProjectionMapping)); }
public async Task <AgreementResult> CreateAgreement(IMarketingAgencyOwner marketingAgencyOwner, Guid providerOrganizationId) { var retVal = new AgreementResult() { ProviderOrganizationId = providerOrganizationId, MarketingOrganizationId = marketingAgencyOwner.OrganizationId }; var marketingOrganization = await _marketingOrganizations.Queryable() .Where(x => x.Id == marketingAgencyOwner.OrganizationId) .FirstOrDefaultAsync(); if (marketingOrganization == null) { retVal.ErrorMessage = "Organization is not configured correctly"; return(retVal); } _logger.LogDebug(GetLogMessage("Marketing Organization Found: {0}"), marketingOrganization.Id); var providerOrganization = await _providerOrganization.Queryable() .Where(x => x.Id == providerOrganizationId) .FirstOrDefaultAsync(); if (providerOrganization == null) { throw new ApplicationException("Provider organization was not found"); } _logger.LogDebug(GetLogMessage("Provider Organization Found: {0}"), providerOrganization.Id); var agreement = new MarketingAgreement { MarketingStream = marketingOrganization.MarketerStream, MarketingBonus = marketingOrganization.MarketerBonus, MarketingAgencyBonus = marketingOrganization.MarketingAgencyBonus, MarketingAgencyStream = marketingOrganization.MarketingAgencyStream, MarketingOrganizationId = marketingAgencyOwner.OrganizationId, ProviderOrganizationId = providerOrganizationId, Status = AgreementStatus.AwaitingApproval, ObjectState = ObjectState.Added, InitiatedByProvider = false, Created = DateTimeOffset.UtcNow }; _logger.LogDebug(GetLogMessage("Marketing Agreement: {@agreement}"), agreement); var result = Repository.InsertOrUpdateGraph(agreement, true); _logger.LogDebug(GetLogMessage("{0} Records updated in database"), result); return(await Task.FromResult(new AgreementResult() { Succeeded = result > 0, MarketingOrganizationId = agreement.MarketingOrganizationId, ProviderOrganizationId = agreement.ProviderOrganizationId })); }
public MarketingAgreementController( IServiceProvider serviceProvider, IMarketingAgencyOwner marketingAgencyOwner, IMarketingAgreementService agreementService) : base(serviceProvider) { _marketingAgencyOwner = marketingAgencyOwner; _agreementService = agreementService; }
public Task <PackedList <T> > GetLeads <T>(IMarketingAgencyOwner ao, CommonFilters filters) where T : AgencyOwnerLeadOutput { return(Repository.Queryable() .ForMarketingAgencyOwner(ao) .Where(x => x.IsInternal == false) .OrderByDescending(x => x.Updated) .PaginateProjection <Lead, T>(filters, ProjectionMapping)); }
public async Task <List <T> > Discover <T>(IMarketingAgencyOwner owner) where T : MarketingAgencyOwnerProviderOrganizationOutput { var exclude = await _marketingAgreement.Queryable() .Where(x => x.MarketingOrganizationId == owner.OrganizationId) .Select(x => x.ProviderOrganizationId).ToListAsync(); exclude.Add(owner.OrganizationId); return(await Repository.Queryable() .Include(x => x.Organization) .ThenInclude(x => x.OrganizationFinancialAccount) .Where(x => !exclude.Contains(x.Id) && x.Organization.OrganizationFinancialAccount != null && x.Discoverable) .ProjectTo <T>(ProjectionMapping).ToListAsync()); }
public async Task <OrganizationResult> UpdateOrganization(IMarketingAgencyOwner agencyOwner, MarketingOrganizationInput input) { _logger.LogInformation(GetLogMessage("Organization:{0}; input:{@input}"), agencyOwner.OrganizationId, input); var marketingOrganization = await Repository.Queryable() .Include(x => x.MarketingOrganization) .Include(x => x.Marketers) .Where(x => x.Id == agencyOwner.OrganizationId) .Select(x => x.MarketingOrganization) .FirstAsync(); var organization = await Repository.Queryable() .Where(x => x.Id == agencyOwner.OrganizationId) .FirstOrDefaultAsync(); return(await UpdateMarketingOrganization(marketingOrganization, input, organization)); }
public async Task <ContractResult> UpdateContract(IMarketingAgencyOwner ao, Guid contractId, UpdateMarketingContractInput input) { var co = await Repository.Queryable().ForAgencyOwner(ao) .FirstAsync(x => x.Id == contractId); co.InjectFrom <NullableInjection>(input); if (input.MarketerStream.HasValue) { co.MarketerStream = input.MarketerStream.Value; } if (input.MarketingAgencyStream.HasValue) { co.MarketingAgencyStream = input.MarketingAgencyStream.Value; } return(await UpdateContract(co)); }
public async Task <AgreementResult> AcceptAgreement( IMarketingAgencyOwner marketingAgencyOwner, Guid providerOrganizationId) { var agreement = await Repository.Queryable() .FirstOrDefaultAsync(x => x.MarketingOrganizationId == marketingAgencyOwner.OrganizationId && x.ProviderOrganizationId == providerOrganizationId); if (agreement == null) { throw new ApplicationException("Agreement not found."); } if (agreement.Status != AgreementStatus.AwaitingApproval) { return new AgreementResult() { Succeeded = false } } ; agreement.Status = AgreementStatus.Approved; agreement.ObjectState = ObjectState.Modified; agreement.Updated = DateTimeOffset.UtcNow; var result = await Repository.UpdateAsync(agreement, true); return(new AgreementResult() { Succeeded = result > 0, MarketingOrganizationId = agreement.MarketingOrganizationId, ProviderOrganizationId = agreement.ProviderOrganizationId }); } }
public static IQueryable <Lead> ForMarketingAgencyOwner(this IQueryable <Lead> entities, IMarketingAgencyOwner ao) { return(entities.Where(x => x.MarketerOrganizationId == ao.OrganizationId)); }
public async Task <MarketingAgencyOwnerTimeMatrixComposedOutput> GetMarketingAgencyComposedOutput(IMarketingAgencyOwner owner, TimeMatrixFilters filters) { // this is essentially the provider organization id filters.MarketerOrganizationId = owner.OrganizationId; var matrix = await _context.TimeMatrix.ApplyWhereFilters(filters) .ProjectTo <MarketingAgencyOwnerTimeMatrixOutput>(_mapperConfiguration) .ToListAsync(); var uniqueMarketerIds = matrix.Select(x => x.MarketerId).Distinct().ToArray(); var marketers = _marketerService.GetForOrganization <AgencyOwnerOrganizationMarketerOutput>(owner.OrganizationId, uniqueMarketerIds); Task.WaitAll(marketers); return(new MarketingAgencyOwnerTimeMatrixComposedOutput { Matrix = matrix, Marketers = marketers.Result }); }
public Task <AgencyOwnerMarketingOrganizationDetailsOutput> GetMarketingDetails(IMarketingAgencyOwner agencyOwner) { return(Repository.Queryable() .Include(x => x.MarketingOrganization) .Where(x => x.MarketingOrganization != null && x.Id == agencyOwner.OrganizationId) .Select(x => x.MarketingOrganization) .ProjectTo <AgencyOwnerMarketingOrganizationDetailsOutput>(ProjectionMapping) .FirstOrDefaultAsync()); }