public SapUnitOfWork(SapContextOptions options)
        {
            //this.InjectInstanceOf(typeof(IRepository), sapSqlDbContext, diApiContext);
            //this.InjectInstanceOf(typeof(IRepository), sapSqlDbContext, diApiContext, options.SqlServerConnection, new DemoItemPropertiesRepository());
            var productPropertiesRepository = new DemoProductPropertiesRepository();

            _options            = options;
            _extrasDbContext    = new RalDbContext(options.ExtrasServerOptions);
            _diApiContext       = new SapDiApiContext(options.DiApiServerConnection, CurrentProvider.GetService <ILogger <SapDiApiContext> >());
            _sapSqlDbContext    = new SapSqlDbContext(options.SapSqlServerOptions);
            BusinessPartners    = new SapBusinessPartnerRepository(_sapSqlDbContext, _diApiContext);
            Salesmen            = new SapSalesmanRepository(_sapSqlDbContext, _diApiContext);
            Employees           = new SapEmployeeRepository(_sapSqlDbContext, _diApiContext);
            Company             = new SapCompanyRepository(_sapSqlDbContext, _diApiContext);
            Quotations          = new SapDocumentRepository <QuotationEntity, QuotationHeaderEntity>(_sapSqlDbContext, _diApiContext, productPropertiesRepository);
            Orders              = new SapDocumentRepository <OrderEntity, OrderHeaderEntity>(_sapSqlDbContext, _diApiContext, productPropertiesRepository);
            DeliveryNotes       = new SapDocumentRepository <DeliveryNoteEntity, DeliveryNoteHeaderEntity>(_sapSqlDbContext, _diApiContext, productPropertiesRepository);
            Invoices            = new SapDocumentRepository <InvoiceEntity, InvoiceHeaderEntity>(_sapSqlDbContext, _diApiContext, productPropertiesRepository);
            CreditNotes         = new SapDocumentRepository <CreditNoteEntity, CreditNoteHeaderEntity>(_sapSqlDbContext, _diApiContext, productPropertiesRepository);
            DownPaymentRequests = new SapDocumentRepository <DownPaymentRequest, DownPaymentRequestHeader>(_sapSqlDbContext, _diApiContext, productPropertiesRepository);

            ProductGroups      = new SapProductGroupRepository(_sapSqlDbContext, _diApiContext);
            Products           = new SapProductRepository(_sapSqlDbContext, _diApiContext);
            RefreshTokens      = new AuthenticationRepository(_extrasDbContext);
            UserLocations      = new UserLocationRepository(_extrasDbContext);
            LeadUsersData      = new LeadUserDataRepository(_extrasDbContext);
            EmployeeTimeClocks = new  EmployeeTimeClockRepository(_extrasDbContext);
            _activities        = new Lazy <IActivityRepository>(new SapActivityRepository(_sapSqlDbContext, _diApiContext, _extrasDbContext, options));
            _attachments       = new Lazy <IAttachmentRepository>(new SapAttachmentRepository(_sapSqlDbContext, _diApiContext));
            _identityUsers     = new Lazy <IIdentityRepository>(new IdentityUserRepository(_extrasDbContext));
        }
        private static IQueryable <TDocumentHeader> SelectDocumentHeaderFromDb(SapSqlDbContext dbContext)
        {
            var docType = typeof(TDocument);

            if (docType == (typeof(QuotationEntity)))
            {
                return(dbContext.OQUT.Select(AsQuotationHeaderEntity) as IQueryable <TDocumentHeader>);
            }
            if (docType == (typeof(OrderEntity)))
            {
                return(dbContext.ORDR.Select(AsOrderHeaderEntity) as IQueryable <TDocumentHeader>);
            }
            if (docType == (typeof(DeliveryNoteEntity)))
            {
                return(dbContext.ODLN.Select(AsDeliveryNoteHeaderEntity) as IQueryable <TDocumentHeader>);
            }
            if (docType == (typeof(InvoiceEntity)))
            {
                return(dbContext.OINV.Select(AsInvoiceHeaderEntity) as IQueryable <TDocumentHeader>);
            }
            if (docType == (typeof(CreditNoteEntity)))
            {
                return(dbContext.ORIN.Select(AsCreditNoteHeaderEntity) as IQueryable <TDocumentHeader>);
            }
            if (docType == (typeof(DownPaymentRequest)))
            {
                return(dbContext.ODPI.Select(AsDownPaymentRequestHeader) as IQueryable <TDocumentHeader>);
            }

            throw new Exception($"Generic type {docType} invalid for DocumentHeaderRepository");
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            SapSqlDbContext sqlDbContex = new SapSqlDbContext();

            sqlDbContex.OCRD.Where(c => c.CardName != null).ToList().ForEach(c => Console.WriteLine(c.CardCode));
        }
 public SapAttachmentRepository(SapSqlDbContext dbContext, SapDiApiContext diApiContext)
     : base(dbContext.ATC1.Select(AsAttachmentEntity),
            x => new IAttachmentRepository.AttachmentKey {
     Code = x.AttachmentsCode.Value, Num = x.Num.Value
 },
            diApiContext.Attachments)
 {
 }
Example #5
0
 private static IQueryable <Activity> SelectActivitiesFromDb(SapSqlDbContext dbContext) =>
 (from oclg in dbContext.OCLG
  join ohem in dbContext.OHEM on oclg.AttendUser equals ohem.userId into gj
  from sub in gj.DefaultIfEmpty()
  select new ActContainer
 {
     Oclg = oclg,
     Ohem = sub
 }).Select(AsActivity);
 public SapDocumentRepository(SapSqlDbContext dbContext, SapDiApiContext diApiContext,
                              IProductPropertiesRepository propertiesRepository)
     : base(SelectDocumentHeaderFromDb(dbContext), x => x.Key.Value)
 {
     _dbContext                = dbContext;
     _diApiContext             = diApiContext;
     _connectionString         = _dbContext.Database.GetDbConnection().ConnectionString;
     _itemPropertiesRepository = propertiesRepository;
     _docType = typeof(TDocument);
 }
Example #7
0
        public SapActivityRepository(SapSqlDbContext dbContext, SapDiApiContext diApiContext,
                                     RalDbContext extraDbContext, SapContextOptions options)
            : base(SelectActivitiesFromDb(dbContext), x => x.Code.Value, diApiContext.Activities)
        {
            _context = dbContext;
            if (_cachedActivities == null)
            {
                _cachedActivities = new Dictionary <int, Activity>();
                extraDbContext.Activities.ForEachAsync(a =>
                {
                    if (a.Code != null)
                    {
                        _cachedActivities[a.Code.Value] = a;
                    }
                }).Wait();
            }
            else
            {
#pragma warning disable 4014
                SyncActivitiesCache(options);
#pragma warning restore 4014
            }
        }
 private static IQueryable <ProductGroupEntity> SelectItemGroupEntity(SapSqlDbContext dbContext)
 {
     return(dbContext.OITB.Select(AsItemGroupEntity));
 }
 public SapProductGroupRepository(SapSqlDbContext dbContext, SapDiApiContext diApiContext)
     : base(SelectItemGroupEntity(dbContext), x => x.Code)
 {
     _dbContext    = dbContext;
     _diApiContext = diApiContext;
 }
Example #10
0
 private static IQueryable <ProductEntity> SelectItems(SapSqlDbContext dbContext)
 {
     return(dbContext.OITM.Select(AsItemEntity));
 }
Example #11
0
 private static IQueryable <SalesmanEntity> SelectSalesmanFromDb(SapSqlDbContext dbContext)
 {
     return(dbContext.OSLP.Select(AsSalesmanEntity).OrderBy(s => s.Sn));
 }
Example #12
0
 public SapSalesmanRepository(SapSqlDbContext dbContext, SapDiApiContext diApiContext)
     : base(SelectSalesmanFromDb(dbContext), x => x.Sn)
 {
     _dbContext    = dbContext;
     _diApiContext = diApiContext;
 }
 public SapCompanyRepository(SapSqlDbContext dbContext, SapDiApiContext diApiContext)
 {
     _dbContext    = dbContext;
     _diApiContext = diApiContext;
 }
Example #14
0
 public SapBusinessPartnerRepository(SapSqlDbContext dbContext, SapDiApiContext diApiContext)
     : base(SelectBusinessPartnerFromDb(dbContext), x => x.Key, diApiContext.BusinessPartners)
 {
     _dbContext    = dbContext;
     _diApiContext = diApiContext;
 }
Example #15
0
 private static IQueryable <BusinessPartner> SelectBusinessPartnerFromDb(SapSqlDbContext dbContext)
 {
     return(dbContext.OCRD
            //    .Where(x => x.CardName != null && x.CardName.Trim() != "")
            .Select(AsCustomerEntity));
 }