public async Task <AccountCode> GetOrCreateAccountCode(string accountCodeName, string accountCodeDescription, IMEXDbContext dbContext, CancellationToken cancellationToken = default) { if (accountCodeName.IsNullOrWhiteSpace()) { return(null); } var accountCode = await dbContext.AccountCodes.FirstOrDefaultAsync(x => x.AccountCodeName.Trim().ToLower() == accountCodeName.Trim().ToLower(), cancellationToken); if (accountCode is null) { accountCode = new AccountCode() { AccountCodeName = accountCodeName, AccountCodeDescription = accountCodeDescription, IsActive = true }; dbContext.AccountCodes.Add(accountCode); } return(accountCode); }
public XeroSupplierImport(IAccountingApiService accountingApi, IMEXDbContext mexDbContext, IAccountCodeService accountCodeService) { this.AccountingApi = accountingApi; this.MexDbContext = mexDbContext; this.AccountCodeService = accountCodeService; }
public MEXPurchaseOrderExport( IFactory <IMEXDbContext> mexDbContextFactory, IMEXDbContext queryDbContext, IAccountingApiService accountingApi, IMapper mapper, IProcessedEntityLogger <PurchaseOrder> processedEntityLogger) { this.MexDbContextFactory = mexDbContextFactory; this.QueryDbContext = queryDbContext; this.AccountingApi = accountingApi; this.Mapper = mapper; this.ProcessedEntityLogger = processedEntityLogger; }
private IAsyncEnumerable <PurchaseOrderLine> GetPurchaseOrderLinesForPo(PurchaseOrder purchaseOrder, IMEXDbContext dbContext) => dbContext.PurchaseOrderLines.Include(x => x.AccountCode) .Include(x => x.Extension_PurchaseOrderLine) .Where(poLine => poLine.PurchaseOrderID == purchaseOrder.PurchaseOrderID) .AsAsyncEnumerable();
private static MethodCallExpression CallAnyOnMifsProcessedEntityLogExpression(IMEXDbContext dbContext, Expression <Func <MifsProcessedEntityLog, bool> > xAnyPredicate) { var xProcessedEntitiesLogProperty = Expression.Property(Expression.Constant(dbContext), nameof(IMEXDbContext.MifsProcessedEntityLogs)); var xAnyCall = Expression.Call(typeof(Enumerable), nameof(Enumerable.Any), new[] { typeof(MifsProcessedEntityLog) }, xProcessedEntitiesLogProperty, xAnyPredicate); return(xAnyCall); }
private static IQueryable <TSource> FilterProcessed <TSource>(this IQueryable <TSource> source, string integrationName, LambdaExpression xSyncFieldLambda, IMEXDbContext dbContext) { var entityType = dbContext.Model.FindEntityType(typeof(TSource)); var primaryKeyProperty = entityType.FindPrimaryKey().Properties.Single(); var xSourceParam = Expression.Parameter(typeof(TSource), "src"); var xPrimaryKey = Expression.Property(xSourceParam, primaryKeyProperty.PropertyInfo); var xLogParam = Expression.Parameter(typeof(MifsProcessedEntityLog), "log"); xSyncFieldLambda = ParameterReplacer.Replace(xSourceParam, xSyncFieldLambda); var xSyncFieldProperty = xSyncFieldLambda?.Body as MemberExpression; var xAnyPredicate = GetMifsLogAnyPredicateExpression <TSource>(xLogParam, xPrimaryKey, integrationName, xSyncFieldProperty); var xAnyCall = CallAnyOnMifsProcessedEntityLogExpression(dbContext, xAnyPredicate); var xNotAny = Expression.Not(xAnyCall); // Creates the lamba src => !dbContext.MifsProcessedEntityLog.Any(log => log.EntityID == src.<PrimaryKey> && log.EntityName == <SrcName>) var xWhereLambda = Expression.Lambda <Func <TSource, bool> >(xNotAny, xSourceParam); return(source.Where(xWhereLambda)); }
public static IQueryable <TSource> FilterProcessed <TSource>(this IQueryable <TSource> source, string integrationName, Expression <Func <PurchaseOrder, DateTime> > syncField, IMEXDbContext dbContext) => source.FilterProcessed(integrationName, (LambdaExpression)syncField, dbContext);
public static IQueryable <TSource> FilterProcessed <TSource>(this IQueryable <TSource> source, string integrationName, IMEXDbContext dbContext) => source.FilterProcessed(integrationName, null, dbContext);
public static IQueryable <PurchaseOrder> FilterApprovalStatus(this IQueryable <PurchaseOrder> source, IMEXDbContext dbContext, params string[] approvalStatusNames) => source.Where(po => approvalStatusNames.Contains(dbContext.RecordApprovals.OrderByDescending(x => x.RecordApprovalID) .FirstOrDefault(recordApproval => recordApproval.EntityID == po.PurchaseOrderID && recordApproval.EntityName == "Purchase Order") .ApprovalStatusName));
public ProcessedEntityLogger(IMEXDbContext dbContext, IConfiguration configuration) { this.DbContext = dbContext; this.IntegrationName = configuration.GetValue <string>("Integration:Name"); }