Exemple #1
0
        private static void Init()
        {
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddLogging(builder => builder.AddSerilog());
            var serviceProvider = serviceCollection.BuildServiceProvider();

            Log.Logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .WriteTo.Console()
                         .CreateLogger();

            var loggerFactory = serviceProvider.GetService <ILoggerFactory>();

            FactoryApplication.SetLoggerFactory(loggerFactory);

            FactoryBusinessOperation.ClearRegisteredItems();
            FactoryBusinessOperation.RegisterBusinessOperations(BusinessErpOperations.GetInstance().ExportedServicesList());

            string       host     = Environment.GetEnvironmentVariable("ONIX_ERP_DB_HOST");
            string       dbname   = Environment.GetEnvironmentVariable("ONIX_ERP_DB_NAME");
            string       user     = Environment.GetEnvironmentVariable("ONIX_ERP_DB_USER");
            string       password = Environment.GetEnvironmentVariable("ONIX_ERP_DB_PASSWORD");
            DbCredential crd      = new DbCredential(host, 5432, dbname, user, password, "pgsql");

            OnixErpDbContext ctx = new OnixErpDbContext(crd);

            ctx.SetLoggerFactory(loggerFactory);
            FactoryBusinessOperation.SetDatabaseContext(ctx);
            FactoryBusinessOperation.SetLoggerFactory(loggerFactory);

            Assembly asm = Assembly.GetExecutingAssembly();

            FactoryDbContext.RegisterDbContext(asm, "OnixErpDbContextPgSql", "OnixBusinessErpApp.OnixErpDbContextPgSql");
        }
Exemple #2
0
        protected override BaseModel Execute(BaseModel dat)
        {
            OnixErpDbContext ctx = (OnixErpDbContext)context;

            CompanyProfile m = (CompanyProfile)dat;

            if ((m.CompanyPrefix != null) && (m.CompanyPrefix.MasterId != null))
            {
                int?id = m.CompanyPrefix.MasterId;
                var o  = ctx.Masters
                         .Where(s => s.MasterId == id)
                         .FirstOrDefault();

                m.CompanyPrefix = o;
            }

            if (ConvertUtils.NullableToInt(m.CompanyProfileId, 0) <= 0)
            {
                m.CompanyProfileId = null;
                ctx.CompanyProfiles.Add(m);
            }
            else
            {
                ctx.CompanyProfiles.Update(m);
            }

            ctx.SaveChanges();
            return(m);
        }
        private IQueryable <CompanyProfile> GetQuery(ParameterExpression startParam, Expression expr)
        {
            OnixErpDbContext ctx = (OnixErpDbContext)context;
            var query            = ctx.CompanyProfiles;

            var lambda  = Expression.Lambda <Func <CompanyProfile, bool> >(expr, startParam);
            var results = query.Where(lambda);

            return(results);
        }
Exemple #4
0
        protected OnixErpDbContext CreateOnixDbContext()
        {
            DbCredential crd = new DbCredential("", 9999, "", "", "", "sqlite_inmem");

            ctx = new OnixErpDbContext(crd);
            ctx.Database.EnsureCreated();

            FactoryBusinessOperation.SetDatabaseContext(ctx);
            return(ctx);
        }
        protected override BaseModel Execute(BaseModel dat)
        {
            OnixErpDbContext ctx = (OnixErpDbContext)context;

            Master m = (Master)dat;

            ctx.Masters.Remove(m);
            ctx.SaveChanges();

            return(m);
        }
        protected override BaseModel Execute(BaseModel dat)
        {
            OnixErpDbContext ctx = (OnixErpDbContext)context;

            CompanyProfile m = (CompanyProfile)dat;

            ctx.CompanyProfiles.Remove(m);
            ctx.SaveChanges();

            return(m);
        }
        protected override BaseModel GetObject(BaseModel dat)
        {
            OnixErpDbContext ctx = (OnixErpDbContext)context;

            CompanyProfile m   = (CompanyProfile)dat;
            string         key = m.Code;

            var o = ctx.CompanyProfiles
                    .Where(s => s.Code.Equals(key))
                    .FirstOrDefault();

            return(o);
        }
        protected override BaseModel GetObject(BaseModel dat)
        {
            OnixErpDbContext ctx = (OnixErpDbContext)context;

            Master m   = (Master)dat;
            string key = m.Code;

            var o = ctx.Masters
                    .Where(s => s.Code.Equals(key))
                    .FirstOrDefault();

            return(o);
        }
        protected override BaseModel GetObject(BaseModel dat)
        {
            OnixErpDbContext ctx = (OnixErpDbContext)context;

            Master m  = (Master)dat;
            int    id = ConvertUtils.NullableToInt(m.MasterId, 0);

            var o = ctx.Masters
                    .Where(s => s.MasterId == id)
                    .FirstOrDefault();

            return(o);
        }
        protected override BaseModel GetObject(BaseModel dat)
        {
            OnixErpDbContext ctx = (OnixErpDbContext)context;

            CompanyProfile m  = (CompanyProfile)dat;
            int            id = ConvertUtils.NullableToInt(m.CompanyProfileId, 0);

            var o = ctx.CompanyProfiles
                    .Where(s => s.CompanyProfileId == id)
                    .Include(c => c.CompanyPrefix)
                    .FirstOrDefault();

            return(o);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddTransient <BaseDbContext>(ctx =>
            {
                var context = new OnixErpDbContext(crd);
                return(context);
            });

            services.AddControllers()
            .AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.Formatting = Formatting.Indented;
            });
        }
        protected override BaseModel Execute(BaseModel dat)
        {
            OnixErpDbContext ctx = (OnixErpDbContext)context;

            Master m = (Master)dat;

            if (ConvertUtils.NullableToInt(m.MasterId, 0) <= 0)
            {
                m.MasterId = null;
                ctx.Masters.Add(m);
            }
            else
            {
                ctx.Masters.Update(m);
            }

            ctx.SaveChanges();
            return(m);
        }
Exemple #13
0
        protected OnixErpDbContext CreateOnixDbContext(string db, string provider)
        {
            OnixErpDbContext ctx = null;

            if (provider.Equals("pgsql"))
            {
                string       host     = Environment.GetEnvironmentVariable("ONIX_ERP_DB_HOST");
                string       dbname   = Environment.GetEnvironmentVariable("ONIX_ERP_DB_NAME");
                string       user     = Environment.GetEnvironmentVariable("ONIX_ERP_DB_USER");
                string       password = Environment.GetEnvironmentVariable("ONIX_ERP_DB_PASSWORD");
                DbCredential crd      = new DbCredential(host, 5432, dbname, user, password, provider);
                ctx = new OnixErpDbContext(crd);
            }
            else if (provider.Equals("sqlite_inmem"))
            {
                DbCredential crd = new DbCredential("", 9999, "", "", "", provider);
                ctx = new OnixErpDbContext(crd);
                ctx.Database.EnsureCreated();
            }

            FactoryBusinessOperation.SetDatabaseContext(ctx);
            return(ctx);
        }