Ejemplo n.º 1
0
        public bool Save(T data, Expression <Func <T, bool> > exp, RepoOptions opts = null)
        {
            SQL <T>        sql   = null;
            IDbTransaction trans = null;

            if (opts != null)
            {
                sql   = opts.AllowedFields == null ? this.SqlBag.AllFieldsSql : this.SqlBag.GetSQLObject(opts.AllowedFields);
                trans = opts.DbTrans;
            }
            else
            {
                sql = this.SqlBag.AllFieldsSql;
            }

            if (trans != null)
            {
                System.Data.Common.DbConnection  conn   = trans?.DbConnection;
                System.Data.Common.DbTransaction dbTran = trans?.DbTransaction;

                return(sql.Save.Execute(data, exp, conn, dbTran));
            }
            else
            {
                using (var conn = this.SqlBag.Database.CreateConnection())
                {
                    conn.Open();
                    return(sql.Save.Execute(data, exp, conn, null));
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <T> GetAsync(Expression <Func <T, bool> > exp, RepoOptions opts = null)
        {
            SQL <T>        sql   = null;
            IDbTransaction trans = null;

            if (opts != null)
            {
                sql   = opts.AllowedFields == null ? this.SqlBag.AllFieldsSql : this.SqlBag.GetSQLObject(opts.AllowedFields);
                trans = opts.DbTrans;
            }
            else
            {
                sql = this.SqlBag.AllFieldsSql;
            }

            if (trans != null)
            {
                System.Data.Common.DbConnection  conn   = trans?.DbConnection;
                System.Data.Common.DbTransaction dbTran = trans?.DbTransaction;

                return(await sql.Get.ExecuteAsync(exp, conn, dbTran));
            }
            else
            {
                using (var conn = this.SqlBag.Database.CreateConnection())
                {
                    await conn.OpenAsync();

                    return(await sql.Get.ExecuteAsync(exp, conn, null));
                }
            }
        }
Ejemplo n.º 3
0
        public bool Insert(T data, RepoOptions opts = null)
        {
            SQL <T>        sql   = null;
            IDbTransaction trans = null;

            if (opts != null)
            {
                sql   = opts.AllowedFields == null ? this.SqlBag.AllFieldsSql : this.SqlBag.GetSQLObject(opts.AllowedFields);
                trans = opts.DbTrans;
            }

            if (trans != null)
            {
                System.Data.Common.DbConnection  conn   = trans.DbConnection;
                System.Data.Common.DbTransaction dbTran = trans.DbTransaction;

                return(sql.Insert.Execute(data, conn, dbTran) == 1);
            }
            else
            {
                using (var conn = this.SqlBag.Database.CreateConnection())
                {
                    conn.Open();
                    return(sql.Insert.Execute(data, conn, null) == 1);
                }
            }
        }
Ejemplo n.º 4
0
        public T GetById(object id, RepoOptions opts = null)
        {
            SQL <T>        sql   = null;
            IDbTransaction trans = null;

            if (opts != null)
            {
                sql   = opts.AllowedFields == null ? this.SqlBag.AllFieldsSql : this.SqlBag.GetSQLObject(opts.AllowedFields);
                trans = opts.DbTrans;
            }
            else
            {
                sql = this.SqlBag.AllFieldsSql;
            }

            if (trans != null)
            {
                System.Data.Common.DbConnection  conn   = trans?.DbConnection;
                System.Data.Common.DbTransaction dbTran = trans?.DbTransaction;

                return(sql.GetById.Execute(id, conn, dbTran));
            }
            else
            {
                using (var conn = this.SqlBag.Database.CreateConnection())
                {
                    conn.Open();
                    return(sql.GetById.Execute(id, conn, null));
                }
            }
        }
Ejemplo n.º 5
0
        public async Task <List <T> > ListAsync(IFilterable <T> filtable, RepoOptions opts = null)
        {
            SQL <T>        sql   = null;
            IDbTransaction trans = null;

            if (opts != null)
            {
                sql   = opts.AllowedFields == null ? this.SqlBag.AllFieldsSql : this.SqlBag.GetSQLObject(opts.AllowedFields);
                trans = opts.DbTrans;
            }
            else
            {
                sql = this.SqlBag.AllFieldsSql;
            }

            if (trans != null)
            {
                System.Data.Common.DbConnection  conn   = trans.DbConnection;
                System.Data.Common.DbTransaction dbTran = trans.DbTransaction;

                return(await sql.Select.ExecuteAsync(filtable, conn, dbTran));
            }
            else
            {
                using (var conn = this.SqlBag.Database.CreateConnection())
                {
                    await conn.OpenAsync();

                    return(await sql.Select.ExecuteAsync(filtable, conn, null));
                }
            }
        }
Ejemplo n.º 6
0
        public async Task <IPageable <T> > PageAsync(IPageable <T> pageable, RepoOptions opts = null)
        {
            var pageInfo = pageable as Pageable <T>;

            if (pageInfo == null)
            {
                pageInfo = new Pageable <T>(pageable);
            }

            SQL <T>        sql   = null;
            IDbTransaction trans = null;

            if (opts != null)
            {
                sql   = opts.AllowedFields == null ? this.SqlBag.AllFieldsSql : this.SqlBag.GetSQLObject(opts.AllowedFields);
                trans = opts.DbTrans;
            }
            else
            {
                sql = this.SqlBag.AllFieldsSql;
            }

            if (trans != null)
            {
                System.Data.Common.DbConnection  conn   = trans.DbConnection;
                System.Data.Common.DbTransaction dbTran = trans.DbTransaction;
                pageInfo.RecordCount = await sql.Count.ExecuteAsync(pageInfo.QueryExpression, conn, dbTran);


                pageInfo.Items = sql.Select.Execute(pageInfo, conn, dbTran);
            }
            else
            {
                using (var conn = this.SqlBag.Database.CreateConnection())
                {
                    await conn.OpenAsync();

                    pageInfo.RecordCount = await sql.Count.ExecuteAsync(pageInfo.QueryExpression, conn, null);


                    pageInfo.Items = await sql.Select.ExecuteAsync(pageInfo, conn, null);
                }
            }

            return(pageInfo);
        }