コード例 #1
0
        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);
        }
コード例 #2
0
 public XeroSupplierImport(IAccountingApiService accountingApi,
                           IMEXDbContext mexDbContext,
                           IAccountCodeService accountCodeService)
 {
     this.AccountingApi      = accountingApi;
     this.MexDbContext       = mexDbContext;
     this.AccountCodeService = accountCodeService;
 }
コード例 #3
0
 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;
 }
コード例 #4
0
 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();
コード例 #5
0
        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);
        }
コード例 #6
0
        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));
        }
コード例 #7
0
 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);
コード例 #8
0
 public static IQueryable <TSource> FilterProcessed <TSource>(this IQueryable <TSource> source, string integrationName, IMEXDbContext dbContext)
 => source.FilterProcessed(integrationName, null, dbContext);
コード例 #9
0
 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));
コード例 #10
0
 public ProcessedEntityLogger(IMEXDbContext dbContext,
                              IConfiguration configuration)
 {
     this.DbContext       = dbContext;
     this.IntegrationName = configuration.GetValue <string>("Integration:Name");
 }